changeset 4271:1eaa8d90c689

fix util.copyfile to deal with symlinks
author Eric St-Jean <esj@wwd.ca>
date Wed, 21 Mar 2007 23:20:56 -0400
parents 29eb88bd5c8d
children ad33eeeeb50a
files mercurial/util.py
diffstat 1 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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"""