[PATCH 2 of 2] localrepo: eliminate os.unlink call in wwrite

Mads Kiilerich mads at kiilerich.com
Sat Dec 4 08:15:05 CST 2010


Adrian Buehlmann wrote, On 12/04/2010 01:39 PM:
> # HG changeset patch
> # User Adrian Buehlmann<adrian at cadifra.com>
> # Date 1291463926 -3600
> # Node ID a68d37f33c943b32bae677c8ef117c4268d10f79
> # Parent  d117e5fec89474724361f2618eddbae350ba29d1
> localrepo: eliminate os.unlink call in wwrite
>
> The opener already unlinks the filename before 'w'riting, for both
> the symlink and the normal file case.
>
> The effect of resetting the flags for normal files is now achieved
> by setting the new resetflags parameter of the opener's __call__
> function to True.
>
> Avoids tripping issue2524 on Windows (os.unlink followed by a write).
>
> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -629,14 +629,10 @@ class localrepository(repo.repository):
>
>       def wwrite(self, filename, data, flags):
>           data = self._filter(self._decodefilterpats, filename, data)
> -        try:
> -            os.unlink(self.wjoin(filename))
> -        except OSError:
> -            pass
>           if 'l' in flags:
>               self.wopener.symlink(data, filename)
>           else:
> -            self.wopener(filename, 'w').write(data)
> +            self.wopener(filename, 'w', resetflags=True).write(data)
>               if 'x' in flags:
>                   util.set_flags(self.wjoin(filename), False, True)

This will go in the opposite direction of what is requested in 
http://mercurial.selenic.com/bts/issue2351 . That might be ok, but I 
still think the "atomic write" patches on 
http://selenic.com/pipermail/mercurial-devel/2010-July/thread.html#22772 
would be nice. Could you perhaps test them on windows or give an updated 
report of your current gut feeling?

Note that another reason to unlink before writing is to break hardlinks 
and getting rid of other meta data (ownership and extended attributes) 
and avoid tripping on other processes reading the old file. At least on 
"unix".

/Mads



More information about the Mercurial-devel mailing list