From: Daniel Dunbar Date: Fri, 6 Mar 2009 18:32:01 +0000 (+0000) Subject: Tidy file removal cleanup & remove race condition on file existence. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6370812b4277134b3c5cd143b20adc8c94890b91;p=clang Tidy file removal cleanup & remove race condition on file existence. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66281 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/ccc/ccclib/Driver.py b/tools/ccc/ccclib/Driver.py index 2015b2f0ed..25984dd74e 100644 --- a/tools/ccc/ccclib/Driver.py +++ b/tools/ccc/ccclib/Driver.py @@ -229,19 +229,27 @@ class Driver(object): self.executeJobs(args, jobs) except: if not args.getLastArg(self.parser.saveTempsOption): - for f in self.resultFiles: - # Fail if removing a result fails: - if os.path.exists(f): - os.remove(f) + # Fail if removing a result fails. + self.removeFiles(self.resultFiles, failOnError=True) raise finally: for f in self.tempFiles: # Ignore failures in removing temporary files - try: - os.remove(f) - except: - pass - + self.removeFiles(self.resultFiles, failOnError=False) + + def removeFiles(self, fileList, failOnError=False): + for f in fileList: + try: + os.remove(f) + except OSError,e: + if failOnError: + import errno + if e.errno != errno.ENOENT: + raise + except: + if failOnError: + raise + def executeJobs(self, args, jobs): vArg = args.getLastArg(self.parser.vOption) for j in jobs.iterjobs():