Don't use shutil.move instead of osutils.rename
John A Meinel
john at arbash-meinel.com
Thu Dec 1 21:59:17 GMT 2005
I'm working on a patch in my win32 fixes branch, I just wanted to make a
comment about this change.
At some point we used to use a fancy delete before rename on win32, and
someone changed that to shutil.move
The problem with shutil.move is that it is completely non-atomic. If it
fails to do a plain rename, it ends up invoking copy2() and then
unlink(), which means that it is will open the source and destination
files, and write bytes between the two. While necessary if you are
moving between filesystems, the big issue here is that if you interrupt
it, you not only don't have your original file, you have some
half-copied file.
Not to mention it would be much slower than just removing and renaming.
If there are cases where we need to handle cross device renames, then we
need to go back to shutil.move (such as moving from a $TMP directory).
But shutil.move is much worse than deleting and then using os.rename.
(The one I will implement will use the same fancy multiple renaming that
sftp.py uses. Basically moving out of the way, moving into place, and if
anything fails reverting the changes.)
John
=:->
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 249 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20051201/589756bf/attachment.pgp
More information about the bazaar
mailing list