[PATCH 2 of 2] Reorder rename operations to minimise risk of leaving repository in unknown state

Patrick Mézard pmezard at gmail.com
Tue Sep 29 04:28:59 CDT 2009


Matt Mackall a écrit :
> 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.

Though I agree the antivirus behaviour is not really nice here, the 'rename files to atomically replace them' paradigm has much less weight on windows than on unix. We would just call os.rename() otherwise.

Looking at MoveFileEx() flags as Sune suggested may help with this, probably at the price or excluding non-(recent?)-NT versions or adding more complexity.

--
Patrick Mézard


More information about the Mercurial-devel mailing list