We don't mind writing empty files if the original file doesn't exist.

This commit is contained in:
Jeremy Fincher 2004-08-02 10:51:57 +00:00
parent 8b780ecc81
commit 1f874cf918

View File

@ -702,8 +702,11 @@ class AtomicFile(file):
def close(self): def close(self):
if not self.rolledback: if not self.rolledback:
super(AtomicFile, self).close() super(AtomicFile, self).close()
# We don't mind writing an empty file if the file we're overwriting
# doesn't exist.
size = os.path.getsize(self.tempFilename) size = os.path.getsize(self.tempFilename)
if size or self.allowEmptyOverwrite: originalExists = os.path.exists(self.filename)
if size or self.allowEmptyOverwrite or not originalExists:
if os.path.exists(self.tempFilename): if os.path.exists(self.tempFilename):
# We use shutil.move here instead of os.rename because # We use shutil.move here instead of os.rename because
# the latter doesn't work on Windows when self.filename # the latter doesn't work on Windows when self.filename