[PATCH 1 of 2] localrepo: use atomictemp when writing files to working directory
Adrian Buehlmann
adrian at cadifra.com
Tue Jul 13 02:39:18 CDT 2010
On 13.07.2010 02:47, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <mads at kiilerich.com>
> # Date 1278981348 -7200
> # Node ID 0fc7d136c17d37d0a9c8d2e41f796a0f9e889aa4
> # Parent f4eddec324b755a45ea71570c7c8dc63bcbdfc1a
> localrepo: use atomictemp when writing files to working directory
>
> Atomictemp has the advantages of automatically breaking hardlinks, avoids
> writing in files already opened by readers, and it will avoid exposing
> partially written files in the working directory.
>
> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -560,9 +560,11 @@
> if 'l' in flags:
> self.wopener.symlink(data, filename)
> else:
> - self.wopener(filename, 'w').write(data)
> + fp = self.wopener(filename, 'w', atomictemp=True)
> + fp.write(data)
> if 'x' in flags:
> - util.set_flags(self.wjoin(filename), False, True)
> + util.set_flags(fp.temp, False, True)
> + fp.rename()
>
> def wwritedata(self, filename, data):
> return self._filter("decode", filename, data)
In my (usually paranoid) gut feelings, atomic temps can make things
worse in presence of those horrid ubiquitous broken on-access virus
scanners on Windows.
More information about the Mercurial-devel
mailing list