[PATCH 2 of 5] util: make atomictempfile avoid ambiguity of file stat if needed
Yuya Nishihara
yuya at tcha.org
Wed May 25 08:39:45 EDT 2016
On Wed, 25 May 2016 01:52:16 +0900, FUJIWARA Katsunori wrote:
> At Tue, 24 May 2016 22:39:26 +0900,
> Yuya Nishihara wrote:
> > On Thu, 19 May 2016 00:26:28 +0900, FUJIWARA Katsunori wrote:
> > > # HG changeset patch
> > > # User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
> > > # Date 1463584838 -32400
> > > # Thu May 19 00:20:38 2016 +0900
> > > # Node ID 561ed91a420adfee1e1386e6dd20fea5ad8c1db5
> > > # Parent dc731ebd60613cf3f08799a8d8dc48435798665b
> > > util: make atomictempfile avoid ambiguity of file stat if needed
> > > + filename = localpath(self.__name)
> > > + oldstat = self._checkambig and filestat(filename)
> > > + if oldstat and oldstat.stat:
> > > + rename(self._tempname, filename)
> > > + newstat = filestat(filename)
> > > + if newstat.isambig(oldstat):
> > > + # stat of changed file is ambiguous to original one
> > > + advanced = (oldstat.stat.st_mtime + 1) & 0x7fffffff
> > > + os.utime(filename, (advanced, advanced))
> >
> > There might be a race if two writers do stat-rename-utime, but we don't care
> > because that would be unavoidable and wouldn't normally happen thanks to
> > wlock/lock. Is that correct?
>
> Yes, this code path is used only for files guarded by wlock/(s)lock,
> and such kind of race should be avoided.
>
> Should it be described in filestat (or clients of it) ?
Yeah, that will help understanding why non-atomic operation is allowed here,
and what will make checkambig=True valid.
More information about the Mercurial-devel
mailing list