[PATCH 2 of 2] Reorder rename operations to minimise risk of leaving repository in unknown state
Matt Mackall
mpm at selenic.com
Mon Sep 28 17:38:47 CDT 2009
On Mon, 2009-09-28 at 17:24 -0500, Steve Borho wrote:
> On Mon, Sep 28, 2009 at 5:00 PM, Laurens Holst <laurens.nospam at grauw.nl> wrote:
> > # HG changeset patch
> > # User Grauw <laurens.hg at grauw.nl>
> > # Date 1254174954 -7200
> > # Node ID c6d8d8a535d478f6fdc00dd6e111c34cf7491c2b
> > # Parent 844c64c7cc2123c5ae16fbfcd27f16fa3e232eca
> > Reorder rename operations to minimise risk of leaving repository in unknown state
> > because of interfering virus scanner. As suggested by Steve Borho, see
> > http://bitbucket.org/tortoisehg/stable/issue/580/#comment-57703
> > Issue 1840 - AVG anti-virus interferes with disk access
> >
> > diff -r 844c64c7cc21 -r c6d8d8a535d4 mercurial/util.py
> > --- a/mercurial/util.py Fri Aug 07 01:15:16 2009 +0200
> > +++ b/mercurial/util.py Mon Sep 28 23:55:54 2009 +0200
> > @@ -444,8 +444,8 @@
> >
> > temp = tempname(dst)
> > os.rename(dst, temp)
> > + os.rename(src, dst)
> > os.unlink(temp)
> > - os.rename(src, dst)
> >
> > def unlink(f):
> > """unlink and remove the directory if it is empty"""
>
> A few of us discussed this issue on IRC today and came to the
> conclusion this change would not have recovered the dirstate file
> Mercurial was attempting to rename. Until the AV tool releases the
> renamed source file, any attempt to rename over the original filename
> will fail.
>
> Since there is very little interest in adding fall-back timers into
> Mercurial to work around unfriendly AV checkers, you're only recourse
> is to figure out how to disable AVG free inside your repository or
> switch to another anti-virus tool. I don't recommend using Mercurial
> with AVG free, as the next time it breaks a rename it could be a file
> that is not as recoverable as dirstate.
I would go further than that. By breaking a bog-standard paradigm of
'rename files to atomically replace them', your antivirus tool is
exposing you to potentially thousands of bugs in thousands of
applications. It's visibly undermining the robustness of your system.
You've spotted and tracked down one such problem, but only because
Mercurial's implementation language has a much stricter exception
paradigm than, say, C, where such fatal errors are routinely blindly
ignored. Adding band-aids to Mercurial will do very little
to address the underlying problem: your antivirus tool is changing the
rules in ways that lead to data corruption.
--
http://selenic.com : development and support for Mercurial and Linux
More information about the Mercurial-devel
mailing list