diff mbox series

fetch2: Ensure GCP fetcher checks if file exists before download.

Message ID 20231127131147.1128798-1-charlie.johnston@loftorbital.com
State Accepted, archived
Commit 1ab1d36c0af6fc58a974106b61ff4d37da6cb229
Headers show
Series fetch2: Ensure GCP fetcher checks if file exists before download. | expand

Commit Message

Charlie Johnston Nov. 27, 2023, 1:11 p.m. UTC
The GCP fetcher was calling bb.fetch2.check_network_access with
"gsutil stat" as the command, but then never actually ran that
command to check if the file exists. In cases where the file did
not exist in a gs:// premirror, this would lead to an unhandled
exception from do_fetch when the GCP python API tried to perform
the download.

This change resolves that issue by adding a runfetchcmd to call
gsutil.

Signed-off-by: Charlie Johnston <charlie.johnston@loftorbital.com>
---
 lib/bb/fetch2/gcp.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/lib/bb/fetch2/gcp.py b/lib/bb/fetch2/gcp.py
index f42c81fd..f40ce2ea 100644
--- a/lib/bb/fetch2/gcp.py
+++ b/lib/bb/fetch2/gcp.py
@@ -47,6 +47,7 @@  class GCP(FetchMethod):
             ud.basename = os.path.basename(ud.path)
 
         ud.localfile = d.expand(urllib.parse.unquote(ud.basename))
+        ud.basecmd = "gsutil stat"
 
     def get_gcp_client(self):
         from google.cloud import storage
@@ -61,7 +62,8 @@  class GCP(FetchMethod):
         if self.gcp_client is None:
             self.get_gcp_client()
 
-        bb.fetch2.check_network_access(d, "gsutil stat", ud.url)
+        bb.fetch2.check_network_access(d, ud.basecmd, f"gs://{ud.host}{ud.path}")
+        runfetchcmd("%s %s" % (ud.basecmd, f"gs://{ud.host}{ud.path}"), d)
 
         # Path sometimes has leading slash, so strip it
         path = ud.path.lstrip("/")
@@ -88,7 +90,8 @@  class GCP(FetchMethod):
         if self.gcp_client is None:
             self.get_gcp_client()
 
-        bb.fetch2.check_network_access(d, "gsutil stat", ud.url)
+        bb.fetch2.check_network_access(d, ud.basecmd, f"gs://{ud.host}{ud.path}")
+        runfetchcmd("%s %s" % (ud.basecmd, f"gs://{ud.host}{ud.path}"), d)
 
         # Path sometimes has leading slash, so strip it
         path = ud.path.lstrip("/")