[PATCH] util.rename: do not abort if os.unlink fails (issue1840)

Adrian Buehlmann adrian at cadifra.com
Tue Oct 6 13:36:07 CDT 2009


On 06.10.2009 20:18, Greg Ward wrote:
> On Tue, Oct 6, 2009 at 5:55 AM, Adrian Buehlmann <adrian at cadifra.com> wrote:
>> # HG changeset patch
>> # User Adrian Buehlmann <adrian at cadifra.com>
>> # Date 1254818723 -7200
>> # Node ID 0aa4141bfb5cc1f033cc2c41dc3d0e1d6a3a2b6f
>> # Parent  d932dc6558812678bb374d66a364212d54503744
>> util.rename: do not abort if os.unlink fails (issue1840)
>>
>> diff --git a/mercurial/util.py b/mercurial/util.py
>> --- a/mercurial/util.py
>> +++ b/mercurial/util.py
>> @@ -427,7 +427,14 @@ def rename(src, dst):
>>
>>         temp = tempname(dst)
>>         os.rename(dst, temp)
>> -        os.unlink(temp)
>> +        try:
>> +            os.unlink(temp)
>> +        except:
>> +            # Some rude AV-scanners on Windows may cause the unlink to
>> +            # fail. Not aborting here just leaks the temp file, whereas
>> +            # aborting at this point may leave serious inconsistencies.
>> +            # Ideally, we would notify the user here.
>> +            pass
>>         os.rename(src, dst)
> 
> That seems sensible to improve hg-stable in the face of broken AV scanners.
> 
> <bikeshedding>
> But it looks like util.rename() is getting awfully hairy just to
> support weird Windows edge cases.  Perhaps it should be split into a
> one-line trivial function in posix.py, and a hairy ugly pile of
> Windows-specific edge cases in windows.py.  Then have util.py import
> one or the other.
> </bikeshedding>

Does that mean you don't want that patch?



More information about the Mercurial-devel mailing list