summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2021-09-28 11:27:24 -0400
committerMike Frysinger <vapier@google.com>2021-09-28 16:06:50 +0000
commit9d96f58f5fcec101c612e61c3e2526ca071d89ea (patch)
tree63bc9e73e3b7d74a2cf5352239bf4f2e9695b507 /project.py
parent7a1e7e772f3bbc67660e824c98f527b5f608ac24 (diff)
downloadgit-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 'project.py')
-rw-r--r--project.py20
1 files changed, 6 insertions, 14 deletions
diff --git a/project.py b/project.py
index fe88a505..634d88c5 100644
--- a/project.py
+++ b/project.py
@@ -1182,10 +1182,8 @@ class Project(object):
1182 self._InitMRef() 1182 self._InitMRef()
1183 else: 1183 else:
1184 self._InitMirrorHead() 1184 self._InitMirrorHead()
1185 try: 1185 platform_utils.remove(os.path.join(self.gitdir, 'FETCH_HEAD'),
1186 platform_utils.remove(os.path.join(self.gitdir, 'FETCH_HEAD')) 1186 missing_ok=True)
1187 except OSError:
1188 pass
1189 return True 1187 return True
1190 1188
1191 def PostRepoUpgrade(self): 1189 def PostRepoUpgrade(self):
@@ -2307,15 +2305,12 @@ class Project(object):
2307 cmd.append('+refs/tags/*:refs/tags/*') 2305 cmd.append('+refs/tags/*:refs/tags/*')
2308 2306
2309 ok = GitCommand(self, cmd, bare=True).Wait() == 0 2307 ok = GitCommand(self, cmd, bare=True).Wait() == 0
2310 if os.path.exists(bundle_dst): 2308 platform_utils.remove(bundle_dst, missing_ok=True)
2311 platform_utils.remove(bundle_dst) 2309 platform_utils.remove(bundle_tmp, missing_ok=True)
2312 if os.path.exists(bundle_tmp):
2313 platform_utils.remove(bundle_tmp)
2314 return ok 2310 return ok
2315 2311
2316 def _FetchBundle(self, srcUrl, tmpPath, dstPath, quiet, verbose): 2312 def _FetchBundle(self, srcUrl, tmpPath, dstPath, quiet, verbose):
2317 if os.path.exists(dstPath): 2313 platform_utils.remove(dstPath, missing_ok=True)
2318 platform_utils.remove(dstPath)
2319 2314
2320 cmd = ['curl', '--fail', '--output', tmpPath, '--netrc', '--location'] 2315 cmd = ['curl', '--fail', '--output', tmpPath, '--netrc', '--location']
2321 if quiet: 2316 if quiet:
@@ -2739,10 +2734,7 @@ class Project(object):
2739 # If the source file doesn't exist, ensure the destination 2734 # If the source file doesn't exist, ensure the destination
2740 # file doesn't either. 2735 # file doesn't either.
2741 if name in symlink_files and not os.path.lexists(src): 2736 if name in symlink_files and not os.path.lexists(src):
2742 try: 2737 platform_utils.remove(dst, missing_ok=True)
2743 platform_utils.remove(dst)
2744 except OSError:
2745 pass
2746 2738
2747 except OSError as e: 2739 except OSError as e:
2748 if e.errno == errno.EPERM: 2740 if e.errno == errno.EPERM: