From 9d96f58f5fcec101c612e61c3e2526ca071d89ea Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 28 Sep 2021 11:27:24 -0400 Subject: 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 Tested-by: Mike Frysinger --- git_config.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'git_config.py') diff --git a/git_config.py b/git_config.py index 778e81a4..bc70d160 100644 --- a/git_config.py +++ b/git_config.py @@ -352,8 +352,8 @@ class GitConfig(object): Trace(': parsing %s', self.file) with open(self._json) as fd: return json.load(fd) - except (IOError, ValueError): - platform_utils.remove(self._json) + except (IOError, ValueErrorl): + platform_utils.remove(self._json, missing_ok=True) return None def _SaveJson(self, cache): @@ -361,8 +361,7 @@ class GitConfig(object): with open(self._json, 'w') as fd: json.dump(cache, fd, indent=2) except (IOError, TypeError): - if os.path.exists(self._json): - platform_utils.remove(self._json) + platform_utils.remove(self._json, missing_ok=True) def _ReadGit(self): """ -- cgit v1.2.3-54-g00ecf