Skip to content

Commit

Permalink
Return destination string instead of the gsutil return value.
Browse files Browse the repository at this point in the history
This is useful as an intermediate step to enable provenance generation
where we need to get the destination location.

Bug: flutter/flutter#115096
Change-Id: I2e2884b177b670b1d23948a950b4b0a5ebcaf652
Reviewed-on: https://flutter-review.googlesource.com/c/recipes/+/36280
Commit-Queue: Godofredo Contreras <godofredoc@google.com>
Reviewed-by: Ricardo Amador <ricardoamador@google.com>
  • Loading branch information
godofredoc authored and CQ Bot Account committed Nov 16, 2022
1 parent bf3f359 commit 9ec04a1
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions recipe_modules/bucket_util/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ def upload_folder(
zip_name: (str) Name of the zip file in the cloud bucket.
platform: (str) Directory name to add the zip file to.
bucket_name: (str) The bucket name. Defaults to flutter_infra.
Returns:
A string with the destination path.
"""
self.upload_folder_and_files(
return self.upload_folder_and_files(
dir_label,
parent_directory,
folder_name,
Expand Down Expand Up @@ -67,6 +70,9 @@ def upload_folder_and_files(
platform: (str) directory name to add the zip file to.
file_paths: (list) A list of string with the filenames to upload.
bucket_name: (str) The bucket name. Defaults to flutter_infra.
Returns:
A string with the destination path.
"""
with self.m.os_utils.make_temp_directory(dir_label) as temp_dir:
remote_name = '%s/%s' % (platform, zip_name) if platform else zip_name
Expand All @@ -82,7 +88,8 @@ def upload_folder_and_files(

pkg.zip('Zip %s' % folder_name)
if self.should_upload_packages():
self.safe_upload(local_zip, remote_zip, bucket_name=bucket_name)
return self.safe_upload(local_zip, remote_zip, bucket_name=bucket_name)


def safe_upload(
self,
Expand Down Expand Up @@ -114,7 +121,7 @@ def safe_upload(
add_mock: (bool) Whether to call path.add_mock_file for the local_path.
Returns:
The result of the gsutil.upload step. Useful for verifying the exit code.
A string with the remote path.
"""
if add_mock:
self.m.path.mock_add_file(local_path)
Expand Down Expand Up @@ -151,13 +158,14 @@ def safe_upload(
return
raise AssertionError('%s already exists on cloud storage' % cloud_path)

return self.m.gsutil.upload(
self.m.gsutil.upload(
local_path,
bucket_name,
remote_path,
args=args,
name='upload "%s"' % remote_path
)
return 'gs://%s/%s' % (bucket_name, remote_path)

def add_files(self, pkg, relative_paths=[]):
"""Adds files to the package.
Expand Down

0 comments on commit 9ec04a1

Please sign in to comment.