From: Lukasz Kosewski Date: Sun, 10 Jan 2010 09:07:10 +0000 (-0500) Subject: index.py: os.rename() fails on Windows if dstfile already exists. X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=49f195951697ef5597336469bb7cbe680d283fc2;p=packages%2Fb%2Fbup.git index.py: os.rename() fails on Windows if dstfile already exists. Hence, we perform an os.unlink on the dstfile if os.rename() receives an OSError exception, and try again. --- diff --git a/index.py b/index.py index 3860087..10ec093 100644 --- a/index.py +++ b/index.py @@ -195,7 +195,12 @@ class Writer: self.f = None if f: f.close() - os.rename(self.tmpname, self.filename) + try: + os.rename(self.tmpname, self.filename) + except OSError: + if os.path.exists(self.filename): + os.unlink(self.filename) + os.rename(self.tmpname, self.filename) def _write(self, data): self.f.write(data)