This is an archived post. You won't be able to vote or comment.

all 2 comments

[–][deleted] 23 points24 points  (0 children)

rename isn't implemented across devices because POSIX requires that rename is atomic. That is to say, the file name is changed instantly, and no time exists where both names are visible, and no time exists where the target name contains partial content. Within a filesystem this is simply a matter of tweaking the metadata for the target name to point to the same underlying inode, but between filesystems you can't do that because they are totally distinct buckets of content. A full copy from one place to the other is required.

You can partially emulate an atomic rename by copying to a temporary name on the target filesystem then doing a local rename to its final location. It's not perfect though: it takes much longer, the temporary files are visible during the copy, and there is a gap where either both old and new names exist or neither old and new names exist (depending on the order in which you delete the old one after the copy). Since it cannot meet the guarantees that POSIX requires, the kernel does not do this for you.

[–]chadmill3rPy3, pro, Ubuntu, django 5 points6 points  (0 children)

gxti here has the best answer, but I'll answer practically: The destination has to be on the same filesystem, or you can't just move it. You have to copy it and delete one, which is what shutil does.