Skip to content

Commit 99d028b

Browse files
athomascommit-bot@chromium.org
authored andcommitted
[infra] Make promote.py work with newer versions of gsutil
Newer versions of gsutil fail when rm -rf'ing non-existing directories. Check if the directory exists before trying to remove it. Change-Id: I57283526f9d13ed5a923b1f5c9d91710ec8d1b60 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/94861 Auto-Submit: Alexander Thomas <athom@google.com> Reviewed-by: William Hesse <whesse@google.com> Commit-Queue: William Hesse <whesse@google.com>
1 parent 9d9f599 commit 99d028b

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

tools/promote.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,26 +104,29 @@ def safety_check_on_gs_path(gs_path, revision, channel):
104104
raise Exception(
105105
"InternalError: Sanity check failed on GS URI: %s" % gs_path)
106106

107+
def exists(gs_path):
108+
(_, _, exit_code) = Gsutil(['ls', gs_path], throw_on_error=False)
109+
# gsutil will exit 0 if the "directory" exists
110+
return exit_code == 0
111+
107112
# Google cloud storage has read-after-write, read-after-update,
108113
# and read-after-delete consistency, but not list after delete consistency.
109114
# Because gsutil uses list to figure out if it should do the unix styly
110115
# copy to or copy into, this means that if the directory is reported as
111116
# still being there (after it has been deleted) gsutil will copy
112117
# into the directory instead of to the directory.
113118
def wait_for_delete_to_be_consistent_with_list(gs_path):
114-
while True:
115-
if DRY_RUN:
116-
break
117-
(_, _, exit_code) = Gsutil(['ls', gs_path], throw_on_error=False)
118-
# gsutil will exit 1 if the "directory" does not exist
119-
if exit_code != 0:
120-
break
119+
if DRY_RUN:
120+
return
121+
while exists(gs_path):
121122
time.sleep(1)
122123

123124
def remove_gs_directory(gs_path):
124125
safety_check_on_gs_path(gs_path, to_revision, channel)
125-
Gsutil(['-m', 'rm', '-R', '-f', gs_path])
126-
wait_for_delete_to_be_consistent_with_list(gs_path)
126+
# Only delete existing directories
127+
if exists(gs_path):
128+
Gsutil(['-m', 'rm', '-R', '-f', gs_path])
129+
wait_for_delete_to_be_consistent_with_list(gs_path)
127130

128131
# Copy sdk directory.
129132
from_loc = raw_namer.sdk_directory(revision)

0 commit comments

Comments
 (0)