[Python-ideas] Implementation of shutil.move

David Townshend aquavitae69 at gmail.com
Mon Aug 15 22:15:05 CEST 2011


On Mon, Aug 15, 2011 at 7:24 PM, Guido van Rossum <guido at python.org> wrote:

> I know I'm late to the party, but I'm surprised that the existing
> behavior of move() is considered problematic. It carefully mimics the
> default behavior of the Unix "mv" command.
>

But "mv" does allow the "-i" (interactive) and "-n" (no-clobber) arguments,
which move() doesn't.


> Doing a move or rename atomically with the provision that it fails
> reliably when the target exists might be useful in some cases, but it
> seems to be more related to filesystem-based locking, which is known
> to be hard in a cross-platform way. (It also seems that some folks on
> the thread have ignored Windows in their use of the term
> "cross-platform".)


That's certainly what I've found in trying to do it! But it seems that it
should be possible on most systems, just each in a different way.  On
windows, it should be as easy as trying os.open(file, os.O_EXEC|os.O_CREAT)
first since windows appears to lock a file to a process when its opened.
 Linux ext file systems (arguably the most common) support an immutable
attribute, also effectively locking the file.  I think that reiserFS and XFS
both has similar features.  Unfortunately I have no experience with OSX or
HPFS so I'm not sure how it would work on a Mac.

This is quite a lot to implement though, so whether its worth it is another
matter... especially since it would be far easier (although slower) to just
copy/remove if it really is a problem.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110815/c5575dd2/attachment.html>


More information about the Python-ideas mailing list