[PATCH STABLE] opener: don't unlink symlinks on 'w'rite

Adrian Buehlmann adrian at cadifra.com
Thu Nov 25 13:29:43 CST 2010


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1290708399 -3600
# Branch stable
# Node ID 29919b4dffb283fc5b84f9dd8ddd946e8b62290d
# Parent  dd24f3e7ca9e68a49fd7f38803e4d98469cad6e4
opener: don't unlink symlinks on 'w'rite

The current code replaces symlinks with a normal file on 'w'rite.

This patch restores the pre 1.7.1 behavior for symlinks, which
preserves them.

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -891,9 +891,12 @@ class opener(object):
             try:
                 if 'w' in mode:
                     st_mode = os.lstat(f).st_mode & 0777
-                    os.unlink(f)
-                    nlink = 0
-                else:
+                    if stat.S_ISLNK(st_mode):
+                        st_mode = None
+                    else:
+                        os.unlink(f)
+                        nlink = 0
+                if st_mode is None:
                     # nlinks() may behave differently for files on Windows
                     # shares if the file is open.
                     fd = open(f)


More information about the Mercurial-devel mailing list