diff options
author | Mike Frysinger <vapier@google.com> | 2021-09-28 11:27:24 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2021-09-28 16:06:50 +0000 |
commit | 9d96f58f5fcec101c612e61c3e2526ca071d89ea (patch) | |
tree | 63bc9e73e3b7d74a2cf5352239bf4f2e9695b507 /subcmds/sync.py | |
parent | 7a1e7e772f3bbc67660e824c98f527b5f608ac24 (diff) | |
download | git-repo-9d96f58f5fcec101c612e61c3e2526ca071d89ea.tar.gz |
make file removal a bit more robust
Some of the file removal calls are subject to race conditions (if
something else deletes the file), so extend our remove API to have
an option to ignore ENOENT errors. Then update a bunch of random
call sites to use this new functionality.
Change-Id: I31a9090e135452033135337a202a4fc2dbf8b63c
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/319195
Reviewed-by: Sean McAllister <smcallis@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'subcmds/sync.py')
-rw-r--r-- | subcmds/sync.py | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py index c99b06ca..3211cbb1 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
@@ -767,13 +767,9 @@ later is required to fix a server side protocol bug. | |||
767 | set(new_copyfile_paths)) | 767 | set(new_copyfile_paths)) |
768 | 768 | ||
769 | for need_remove_file in need_remove_files: | 769 | for need_remove_file in need_remove_files: |
770 | try: | 770 | # Try to remove the updated copyfile or linkfile. |
771 | platform_utils.remove(need_remove_file) | 771 | # So, if the file is not exist, nothing need to do. |
772 | except OSError as e: | 772 | platform_utils.remove(need_remove_file, missing_ok=True) |
773 | if e.errno == errno.ENOENT: | ||
774 | # Try to remove the updated copyfile or linkfile. | ||
775 | # So, if the file is not exist, nothing need to do. | ||
776 | pass | ||
777 | 773 | ||
778 | # Create copy-link-files.json, save dest path of "copyfile" and "linkfile". | 774 | # Create copy-link-files.json, save dest path of "copyfile" and "linkfile". |
779 | with open(copylinkfile_path, 'w', encoding='utf-8') as fp: | 775 | with open(copylinkfile_path, 'w', encoding='utf-8') as fp: |
@@ -1171,10 +1167,7 @@ class _FetchTimes(object): | |||
1171 | with open(self._path) as f: | 1167 | with open(self._path) as f: |
1172 | self._times = json.load(f) | 1168 | self._times = json.load(f) |
1173 | except (IOError, ValueError): | 1169 | except (IOError, ValueError): |
1174 | try: | 1170 | platform_utils.remove(self._path, missing_ok=True) |
1175 | platform_utils.remove(self._path) | ||
1176 | except OSError: | ||
1177 | pass | ||
1178 | self._times = {} | 1171 | self._times = {} |
1179 | 1172 | ||
1180 | def Save(self): | 1173 | def Save(self): |
@@ -1192,10 +1185,7 @@ class _FetchTimes(object): | |||
1192 | with open(self._path, 'w') as f: | 1185 | with open(self._path, 'w') as f: |
1193 | json.dump(self._times, f, indent=2) | 1186 | json.dump(self._times, f, indent=2) |
1194 | except (IOError, TypeError): | 1187 | except (IOError, TypeError): |
1195 | try: | 1188 | platform_utils.remove(self._path, missing_ok=True) |
1196 | platform_utils.remove(self._path) | ||
1197 | except OSError: | ||
1198 | pass | ||
1199 | 1189 | ||
1200 | # This is a replacement for xmlrpc.client.Transport using urllib2 | 1190 | # This is a replacement for xmlrpc.client.Transport using urllib2 |
1201 | # and supporting persistent-http[s]. It cannot change hosts from | 1191 | # and supporting persistent-http[s]. It cannot change hosts from |