diff options
Diffstat (limited to 'bitbake/lib/bb/fetch2/gcp.py')
-rw-r--r-- | bitbake/lib/bb/fetch2/gcp.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/bitbake/lib/bb/fetch2/gcp.py b/bitbake/lib/bb/fetch2/gcp.py index f40ce2eaa5..86546d40bf 100644 --- a/bitbake/lib/bb/fetch2/gcp.py +++ b/bitbake/lib/bb/fetch2/gcp.py | |||
@@ -46,8 +46,7 @@ class GCP(FetchMethod): | |||
46 | else: | 46 | else: |
47 | ud.basename = os.path.basename(ud.path) | 47 | ud.basename = os.path.basename(ud.path) |
48 | 48 | ||
49 | ud.localfile = d.expand(urllib.parse.unquote(ud.basename)) | 49 | ud.localfile = ud.basename |
50 | ud.basecmd = "gsutil stat" | ||
51 | 50 | ||
52 | def get_gcp_client(self): | 51 | def get_gcp_client(self): |
53 | from google.cloud import storage | 52 | from google.cloud import storage |
@@ -58,17 +57,20 @@ class GCP(FetchMethod): | |||
58 | Fetch urls using the GCP API. | 57 | Fetch urls using the GCP API. |
59 | Assumes localpath was called first. | 58 | Assumes localpath was called first. |
60 | """ | 59 | """ |
60 | from google.api_core.exceptions import NotFound | ||
61 | logger.debug2(f"Trying to download gs://{ud.host}{ud.path} to {ud.localpath}") | 61 | logger.debug2(f"Trying to download gs://{ud.host}{ud.path} to {ud.localpath}") |
62 | if self.gcp_client is None: | 62 | if self.gcp_client is None: |
63 | self.get_gcp_client() | 63 | self.get_gcp_client() |
64 | 64 | ||
65 | bb.fetch2.check_network_access(d, ud.basecmd, f"gs://{ud.host}{ud.path}") | 65 | bb.fetch2.check_network_access(d, "blob.download_to_filename", f"gs://{ud.host}{ud.path}") |
66 | runfetchcmd("%s %s" % (ud.basecmd, f"gs://{ud.host}{ud.path}"), d) | ||
67 | 66 | ||
68 | # Path sometimes has leading slash, so strip it | 67 | # Path sometimes has leading slash, so strip it |
69 | path = ud.path.lstrip("/") | 68 | path = ud.path.lstrip("/") |
70 | blob = self.gcp_client.bucket(ud.host).blob(path) | 69 | blob = self.gcp_client.bucket(ud.host).blob(path) |
71 | blob.download_to_filename(ud.localpath) | 70 | try: |
71 | blob.download_to_filename(ud.localpath) | ||
72 | except NotFound: | ||
73 | raise FetchError("The GCP API threw a NotFound exception") | ||
72 | 74 | ||
73 | # Additional sanity checks copied from the wget class (although there | 75 | # Additional sanity checks copied from the wget class (although there |
74 | # are no known issues which mean these are required, treat the GCP API | 76 | # are no known issues which mean these are required, treat the GCP API |
@@ -90,8 +92,7 @@ class GCP(FetchMethod): | |||
90 | if self.gcp_client is None: | 92 | if self.gcp_client is None: |
91 | self.get_gcp_client() | 93 | self.get_gcp_client() |
92 | 94 | ||
93 | bb.fetch2.check_network_access(d, ud.basecmd, f"gs://{ud.host}{ud.path}") | 95 | bb.fetch2.check_network_access(d, "gcp_client.bucket(ud.host).blob(path).exists()", f"gs://{ud.host}{ud.path}") |
94 | runfetchcmd("%s %s" % (ud.basecmd, f"gs://{ud.host}{ud.path}"), d) | ||
95 | 96 | ||
96 | # Path sometimes has leading slash, so strip it | 97 | # Path sometimes has leading slash, so strip it |
97 | path = ud.path.lstrip("/") | 98 | path = ud.path.lstrip("/") |