transaction: do not overwrite atomic-temp files on error
authorYuya Nishihara <yuya@tcha.org>
Sun, 23 Dec 2018 12:39:20 +0900
changeset 41107 3e2c02836420
parent 41106 dc56a6273575
child 41108 38e88450138c
transaction: do not overwrite atomic-temp files on error Even though the original files can be restored from the backup, it should be better to not write back a temporary file if we know it can be corrupted.
mercurial/transaction.py
--- a/mercurial/transaction.py	Thu Jan 03 10:13:34 2019 -0800
+++ b/mercurial/transaction.py	Sun Dec 23 12:39:20 2018 +0900
@@ -347,9 +347,13 @@
                     files.append(vfs(name, 'w', atomictemp=True,
                                      checkambig=checkambig))
                 genfunc(*files)
+                for f in files:
+                    f.close()
+                # skip discard() loop since we're sure no open file remains
+                del files[:]
             finally:
                 for f in files:
-                    f.close()
+                    f.discard()
         return any
 
     @active