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

login
register
mail settings
Submitter Pierre-Yves David
Date Jan. 17, 2015, 12:47 a.m.
Message ID <3e5891e0ec1e22afb9aa.1421455664@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/7507/
State Accepted
Commit 5eb3541f907efe47dcb1bf03bc1437316942a5cf
Headers show

Comments

Pierre-Yves David - Jan. 17, 2015, 12:47 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@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.
Matt Mackall - Jan. 17, 2015, 12:54 a.m.
On Fri, 2015-01-16 at 16:47 -0800, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@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

These are queued for default, thanks.

Patch

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))