changeset 41107:3e2c02836420

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.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 23 Dec 2018 12:39:20 +0900
parents dc56a6273575
children 38e88450138c
files mercurial/transaction.py
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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