Catch OSError when renaming and try to remove the destination file first
Otherwise the rename fails on Windows if the destination file already exists. Change-Id: Id15cfaa5b9278d7e932a7975ab6e5a878b31a642
This commit is contained in:
parent
6e4b760655
commit
df1ab0f01a
|
@ -110,7 +110,13 @@ class CacheStorage(object):
|
||||||
tfile.flush()
|
tfile.flush()
|
||||||
self._os.fsync(tfile.fileno())
|
self._os.fsync(tfile.fileno())
|
||||||
tfile.close()
|
tfile.close()
|
||||||
self._os.rename(tfile.name, self.cachefilename)
|
try:
|
||||||
|
self._os.rename(tfile.name, self.cachefilename)
|
||||||
|
except OSError:
|
||||||
|
# On Windows, if dst already exists, OSError will be raised even if
|
||||||
|
# it is a file. Remove the file first in that case and try again.
|
||||||
|
self._os.remove(self.cachefilename)
|
||||||
|
self._os.rename(tfile.name, self.cachefilename)
|
||||||
|
|
||||||
self._logger.debug("Cache written out to '%s'" % self.cachefilename)
|
self._logger.debug("Cache written out to '%s'" % self.cachefilename)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue