Patchwork [5,of,7] util.copyfiles: add optional overwrite parameter

login
register
mail settings
Submitter Angel Ezquerra
Date Nov. 25, 2015, 12:22 a.m.
Message ID <ec9de3a84179e1e3531d.1448410949@waste.org>
Download mbox | patch
Permalink /patch/11635/
State Changes Requested
Headers show

Comments

Angel Ezquerra - Nov. 25, 2015, 12:22 a.m.
# HG changeset patch
# User Angel Ezquerra <angel.ezquerra@gmail.com>
# Date 1448233986 -3600
#      Mon Nov 23 00:13:06 2015 +0100
# Node ID ec9de3a84179e1e3531d784b1f15d988a33f5455
# Parent  f275c1ff2148e806e45ea308139b0ff28b74b270
util.copyfiles: add optional overwrite parameter

Make it possible to change the default util.copyfiles behavior, which is to
overwrite the existing files.

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -799,7 +799,8 @@ 
         except shutil.Error as inst:
             raise Abort(str(inst))
 
-def copyfiles(src, dst, hardlink=None, progress=lambda t, pos: None):
+def copyfiles(src, dst, hardlink=None, progress=lambda t, pos: None,
+              overwrite=True):
     """Copy a directory tree using hardlinks if possible."""
     num = 0
 
@@ -820,8 +821,11 @@ 
             def nprog(t, pos):
                 if pos is not None:
                     return progress(t, pos + num)
-            hardlink, n = copyfiles(srcname, dstname, hardlink, progress=nprog)
+            hardlink, n = copyfiles(srcname, dstname, hardlink, progress=nprog,
+                                    overwrite=overwrite)
             num += n
+    elif not overwrite and os.path.exists(dst):
+        pass
     else:
         if hardlink:
             try: