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

Steve Borho steve at borho.org
Thu Nov 25 13:52:11 CST 2010


On Thu, Nov 25, 2010 at 1:29 PM, Adrian Buehlmann <adrian at cadifra.com> wrote:
> # 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.

This looks like it needs a test.

> 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)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>



-- 
Steve Borho


More information about the Mercurial-devel mailing list