Commit a1fbdff1 authored by Yuwei Huang's avatar Yuwei Huang Committed by Commit Bot

Fix filename sorting logic in git_cache.py

We have trouble rolling dep of the grpc library. It looks like buildbots
use git_cache to download cache of the library from cloud storage, but
the way it picks up the latest cache is to do a string sort on the
filenames then pick the last one. This won't work if the filenames have
digit carrying, say you have both 9999.zip and 10000.zip, then 9999.zip
will get picked up.

This CL fixes this by implementing a new filename sorting logic that
extracts the numeral part of the filename and sort on it.

Bug: 927154
Change-Id: I68fce3fe67e55ce5092e7e9dc1dca606b427fe87
Reviewed-on: https://chromium-review.googlesource.com/c/1448954
Commit-Queue: Yuwei Huang <yuweih@chromium.org>
Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: 's avatarRobbie Iannucci <iannucci@chromium.org>
parent 4f738c1f
......@@ -368,7 +368,23 @@ class Mirror(object):
gsutil = Gsutil(self.gsutil_exe, boto_path=None)
# Get the most recent version of the zipfile.
_, ls_out, ls_err = gsutil.check_call('ls', gs_folder)
ls_out_sorted = sorted(ls_out.splitlines())
def compare_filenames(a, b):
# |a| and |b| look like gs://.../.../9999.zip. They both have the same
# gs://bootstrap_bucket/basedir/ prefix because they come from the same
# `gsutil ls`.
# This function only compares the numeral parts before .zip.
regex_pattern = r'/(\d+)\.zip$'
match_a = re.search(regex_pattern, a)
match_b = re.search(regex_pattern, b)
if (match_a is not None) and (match_b is not None):
num_a = int(match_a.group(1))
num_b = int(match_b.group(1))
return cmp(num_a, num_b)
# If it doesn't match the format, fallback to string comparison.
return cmp(a, b)
ls_out_sorted = sorted(ls_out.splitlines(), cmp=compare_filenames)
if not ls_out_sorted:
# This repo is not on Google Storage.
self.print('No bootstrap file for %s found in %s, stderr:\n %s' %
......
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