[PATCH STABLE V2] opener: do not unlink symlinks on 'w'rite

Adrian Buehlmann adrian at cadifra.com
Fri Nov 26 17:20:42 CST 2010


On 2010-11-25 23:40, Adrian Buehlmann wrote:
> # HG changeset patch
> # User Adrian Buehlmann <adrian at cadifra.com>
> # Date 1290708399 -3600
> # Branch stable
> # Node ID 0162f745b6ba9f422e22c71f03b0c7d91a17cacb
> # Parent  dd24f3e7ca9e68a49fd7f38803e4d98469cad6e4
> opener: do not 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, which preserves symlinks.
> 
> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -890,10 +890,13 @@ class opener(object):
>                  return atomictempfile(f, mode, self.createmode)
>              try:
>                  if 'w' in mode:
> -                    st_mode = os.lstat(f).st_mode & 0777
> -                    os.unlink(f)
> -                    nlink = 0
> -                else:
> +                    st_mode = os.lstat(f).st_mode
> +                    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)
> @@ -913,7 +916,7 @@ class opener(object):
>              if st_mode is None:
>                  self._fixfilemode(f)
>              else:
> -                os.chmod(f, st_mode)
> +                os.chmod(f, st_mode & 0777)
>          return fp
>  
>      def symlink(self, src, dst):

I'm putting this patch on hold. Please don't push it.

Greg seems to anyway have solved his problem with his extension and I'm
not aware of anything in Mercurial that would need this change here.

So it is probably not worth the complexity increase and the risk.


More information about the Mercurial-devel mailing list