Allow rolling crate upgrades back.
Currently, if an error occurs after we overwrite the previous version
of the crate with a new one, we can end up in either of two bad
states. If the error is hidden (e.g., when generating TEST_MAPPING),
the updater proceeds as normal, which can result in uploading an
invalid CL (although it does often mark it as Verified - 1). Worse,
if the error is visible (e.g., git commit fails), the bad files are
left in the current directory, which if they contain a build error,
can cause all future upgrades to fail.
We fix this by keeping the previous version of the crate around (a
comment in the code suggests that it did this, but it did not). If
the updater encounters an error, it rolls back to that saved copy.
We have to be careful not to try to rollback if we haven't swapped
to the new crate yet, however.
Note that this is currently only implemented for crates. The
GithubArchiveUpdater has similar code and could probably do the same
thing; the GitUpdater would do it differently.
Test: Run with and without errors.
Change-Id: Ia48660ad72cb3ea1689d92f880ff033e9c35aed9
diff --git a/updater_utils.py b/updater_utils.py
index 1bcd567..209a1cd 100644
--- a/updater_utils.py
+++ b/updater_utils.py
@@ -48,7 +48,7 @@
raise ValueError('No supported URL.')
-def replace_package(source_dir, target_dir) -> None:
+def replace_package(source_dir, target_dir, temp_file=None) -> None:
"""Invokes a shell script to prepare and update a project.
Args:
@@ -59,7 +59,8 @@
print('Updating {} using {}.'.format(target_dir, source_dir))
script_path = os.path.join(os.path.dirname(sys.argv[0]),
'update_package.sh')
- subprocess.check_call(['bash', script_path, source_dir, target_dir])
+ subprocess.check_call(['bash', script_path, source_dir, target_dir,
+ "" if temp_file is None else temp_file])
VERSION_SPLITTER_PATTERN: str = r'[\.\-_]'