Commit 04ce146c authored by aiolos's avatar aiolos Committed by Commit bot

Make bucket required for GetIfChanged.

BUG=419551

Review URL: https://codereview.chromium.org/893963003

Cr-Commit-Position: refs/heads/master@{#315169}
parent fd948717
...@@ -216,7 +216,7 @@ def Insert(bucket, remote_path, local_path, publicly_readable=False): ...@@ -216,7 +216,7 @@ def Insert(bucket, remote_path, local_path, publicly_readable=False):
bucket, remote_path) bucket, remote_path)
def GetIfChanged(file_path, bucket=None): def GetIfChanged(file_path, bucket):
"""Gets the file at file_path if it has a hash file that doesn't match. """Gets the file at file_path if it has a hash file that doesn't match.
If the file is not in Cloud Storage, log a warning instead of raising an If the file is not in Cloud Storage, log a warning instead of raising an
...@@ -224,6 +224,10 @@ def GetIfChanged(file_path, bucket=None): ...@@ -224,6 +224,10 @@ def GetIfChanged(file_path, bucket=None):
Returns: Returns:
True if the binary was changed. True if the binary was changed.
Raises:
CredentialsError if the user has no configured credentials.
PermissionError if the user does not have permission to access the bucket.
NotFoundError if the file is not in the given bucket in cloud_storage.
""" """
hash_path = file_path + '.sha1' hash_path = file_path + '.sha1'
if not os.path.exists(hash_path): if not os.path.exists(hash_path):
...@@ -234,20 +238,8 @@ def GetIfChanged(file_path, bucket=None): ...@@ -234,20 +238,8 @@ def GetIfChanged(file_path, bucket=None):
if os.path.exists(file_path) and CalculateHash(file_path) == expected_hash: if os.path.exists(file_path) and CalculateHash(file_path) == expected_hash:
return False return False
if bucket: Get(bucket, expected_hash, file_path)
buckets = [bucket] return True
else:
buckets = [PUBLIC_BUCKET, PARTNER_BUCKET, INTERNAL_BUCKET]
for bucket in buckets:
try:
Get(bucket, expected_hash, file_path)
return True
except NotFoundError:
continue
logging.warning('Unable to find file in Cloud Storage: %s', file_path)
return False
def CalculateHash(file_path): def CalculateHash(file_path):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment