[PATCH] for issue 516 - can't revert or rename a symlink to a directory

Eric St-Jean esj at wwd.ca
Wed Mar 14 11:56:23 CDT 2007


This should fix issue 516.
Patch attached which fixes all issues: rename and revert a symbolic link
which
points to a directory (doesn't matter what it points to in the repo; the
bug is
triggered by the link currently pointing to a dir), and reverting a dangling
symlink will (correctly, i think) save the original link in *.orig.
I don't think the patch breaks anything, but i also do not think it's
all correct wrt OS-abstraction. I tried to make it so it should work on
nt, but maybe it wouldn't.
-------------- next part --------------
# HG changeset patch
# User Eric St-Jean <eric.st-jean at jeppesen.com>
# Date 1173846350 14400
# Node ID 3e0aac81c5dc32d7d55bfb31f954c7bd3ff58333
# Parent  c0271aba6abe6f5c9da103bafb10821a84dc6140
First shot at issue 516: big with reverting / renaming a symlink which now points to a directory

diff -r c0271aba6abe -r 3e0aac81c5dc mercurial/commands.py
--- a/mercurial/commands.py	Thu Mar 08 20:08:24 2007 -0300
+++ b/mercurial/commands.py	Wed Mar 14 00:25:50 2007 -0400
@@ -2203,7 +2203,7 @@ def revert(ui, repo, *pats, **opts):
         def handle(xlist, dobackup):
             xlist[0].append(abs)
             update[abs] = 1
-            if dobackup and not opts['no_backup'] and os.path.exists(rel):
+            if dobackup and not opts['no_backup'] and (util.is_link(rel) or os.path.exists(rel)):
                 bakname = "%s.orig" % rel
                 ui.note(_('saving current version of %s as %s\n') %
                         (rel, bakname))
@@ -3304,3 +3304,4 @@ def dispatch(args):
         raise
 
     return -1
+run()
\ No newline at end of file
diff -r c0271aba6abe -r 3e0aac81c5dc mercurial/localrepo.py
--- a/mercurial/localrepo.py	Thu Mar 08 20:08:24 2007 -0300
+++ b/mercurial/localrepo.py	Wed Mar 14 00:25:50 2007 -0400
@@ -1040,10 +1040,10 @@ class localrepository(repo.repository):
 
     def copy(self, source, dest, wlock=None):
         p = self.wjoin(dest)
-        if not os.path.exists(p):
+        if not (os.path.exists(p) or self._link(p)):
             self.ui.warn(_("%s does not exist!\n") % dest)
-        elif not os.path.isfile(p):
-            self.ui.warn(_("copy failed: %s is not a file\n") % dest)
+        elif not (os.path.isfile(p) or self._link(p)):
+            self.ui.warn(_("copy failed: %s is not a file or a symbolic link\n") % dest)
         else:
             if not wlock:
                 wlock = self.wlock()
diff -r c0271aba6abe -r 3e0aac81c5dc mercurial/util.py
--- a/mercurial/util.py	Thu Mar 08 20:08:24 2007 -0300
+++ b/mercurial/util.py	Wed Mar 14 00:25:50 2007 -0400
@@ -591,8 +591,14 @@ def copyfile(src, dest):
 def copyfile(src, dest):
     "copy a file, preserving mode"
     try:
-        shutil.copyfile(src, dest)
-        shutil.copymode(src, dest)
+        if is_link(src):
+            try:
+                os.symlink(os.readlink(src),dest)
+            except OSError:
+                open(dst,'w').write(os.readlink(src))
+        else:
+            shutil.copyfile(src, dest)
+            shutil.copymode(src, dest)
     except shutil.Error, inst:
         raise Abort(str(inst))
 
@@ -616,6 +622,11 @@ def copyfiles(src, dst, hardlink=None):
             except (IOError, OSError):
                 hardlink = False
                 shutil.copy(src, dst)
+        elif is_link(src):
+            try:
+                os.symlink(os.readlink(src),dest)
+            except OSError:
+                open(dst,'w').write(os.readlink(src))
         else:
             shutil.copy(src, dst)
 
@@ -836,6 +847,9 @@ if os.name == 'nt':
     def set_link(f, mode):
         pass
 
+    def is_link(f):
+        return False
+    
     def set_binary(fd):
         msvcrt.setmode(fd.fileno(), os.O_BINARY)
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: esj.vcf
Type: text/x-vcard
Size: 161 bytes
Desc: not available
Url : http://www.selenic.com/pipermail/mercurial-devel/attachments/20070314/08f2fa6f/esj.vcf


More information about the Mercurial-devel mailing list