lib: allow building without private mirror name file
To build a public COS image, a user doesn't need to have
the private mirror name file in the private repo.
BUG=b/378556947
TEST=presubmit
RELEASE_NOTE=None
Change-Id: I7608c5090e247975941f35e6bd393d4f456ea14f
diff --git a/lib/gs.py b/lib/gs.py
index f6f1545..14a1066 100644
--- a/lib/gs.py
+++ b/lib/gs.py
@@ -1230,15 +1230,23 @@
"""
# Download from COS private mirror.
- with open(
- self._PRIVATE_MIRROR_NAME_FILE, "r", encoding="utf-8"
- ) as file:
- mirror_name = file.read()
- if src_path.startswith(mirror_name):
- print("Trying downloading with mirror SA token.")
- token = self._GetMirrorSAToken()
- self._DownloadWithToken(token, src_path, dest_path)
- return
+ try:
+ with open(
+ self._PRIVATE_MIRROR_NAME_FILE, "r", encoding="utf-8"
+ ) as file:
+ mirror_name = file.read()
+ if src_path.startswith(mirror_name):
+ print("Trying downloading with mirror SA token.")
+ token = self._GetMirrorSAToken()
+ self._DownloadWithToken(token, src_path, dest_path)
+ return
+ except FileNotFoundError:
+ # To build a public COS image, a user doesn't need to have
+ # self._PRIVATE_MIRROR_NAME_FILE in the private repo.
+ print(
+ f"file {self._PRIVATE_MIRROR_NAME_FILE} not found, "
+ "cannot download packages from COS private mirror."
+ )
# -v causes gs://bucket/path#generation to be listed in output.
cmd = ["cp", "-v"]