[PATCH 2 of 2] transaction: use 'util.copyfile' for creating backup

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri Jan 16 18:47:44 CST 2015


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1420490655 28800
#      Mon Jan 05 12:44:15 2015 -0800
# Node ID 3e5891e0ec1e22afb9aafa0b3155ef3fa4c03825
# Parent  28ab98266efd7717443607d4ecb30d036ef03452
transaction: use 'util.copyfile' for creating backup

Using 'copyfile' (single file) instead of 'copyfiles' (tree) will ensures
destination file will be overwritten. This will prevent some abort if backup
file are left in place for random reason.

It also seems more correct.

diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -204,11 +204,11 @@ class transaction(object):
         backupfilename = "%s.backup.%s" % (self.journal, filename)
         backupfile = vfs.reljoin(dirname, backupfilename)
         if vfs.exists(file):
             filepath = vfs.join(file)
             backuppath = vfs.join(backupfile)
-            util.copyfiles(filepath, backuppath, hardlink=hardlink)
+            util.copyfile(filepath, backuppath, hardlink=hardlink)
         else:
             backupfile = ''
 
         self._addbackupentry((location, file, backupfile, False))
 


More information about the Mercurial-devel mailing list