[PATCH 05 of 11] cmdutil: securely rename a to A on disk

Simon Heimberg simohe at besonet.ch
Tue Aug 11 07:36:05 CDT 2009


Am Dienstag, den 11.08.2009, 13:41 +0200 schrieb Martin Geisler:
> Simon Heimberg <simohe at besonet.ch> writes:
> 
> > def temprename(src):
> >     """renames a file to a temporary name
> >        the new name is returned"""
> >     temp = tempname.mktemp(suffix='tmpmv', dir=os.path.dirname(src))
> >     os.rename(src, temp)
> >     return temp
> >
> > Is there a reason why tempname.mktemp was not used?
> 
> Yes, it is explained in the big comment just above the tempname function
> you moved :-)
> 
> Short summary: an eager antivirus program might open the file created by
> mktemp, and thereby lock the file under Windows.
> 
> So please move this rather important comment too, if you move the
> function it applies to.
> 
mktemp does not create anything (this is mkstemp), it does (almost) the
same as the code in the loop does.
The comment belongs to the exception in rename. But I could move the
last to lines.
mktemp is deprecated since Python 2.3. It is still there in 3.1 and
according to [1] it is unlikely that it is removed. The warning in its
code is commented out since a long time. So maybe we can use it.

[1] http://mail.python.org/pipermail/python-3000/2007-August/009938.html


More information about the Mercurial-devel mailing list