fix util.copyfile to deal with symlinks
authorEric St-Jean <esj@wwd.ca>
Wed, 21 Mar 2007 23:20:56 -0400
changeset 4271 1eaa8d90c689
parent 4270 29eb88bd5c8d
child 4272 ad33eeeeb50a
fix util.copyfile to deal with symlinks
mercurial/util.py
--- a/mercurial/util.py	Fri Mar 23 14:11:31 2007 -0700
+++ b/mercurial/util.py	Wed Mar 21 23:20:56 2007 -0400
@@ -614,11 +614,18 @@
 
 def copyfile(src, dest):
     "copy a file, preserving mode"
-    try:
-        shutil.copyfile(src, dest)
-        shutil.copymode(src, dest)
-    except shutil.Error, inst:
-        raise Abort(str(inst))
+    if os.path.islink(src):
+        try:
+            os.unlink(dest)
+        except:
+            pass
+        os.symlink(os.readlink(src), dest)
+    else:
+        try:
+            shutil.copyfile(src, dest)
+            shutil.copymode(src, dest)
+        except shutil.Error, inst:
+            raise Abort(str(inst))
 
 def copyfiles(src, dst, hardlink=None):
     """Copy a directory tree using hardlinks if possible"""