pyfilesystem2
pyfilesystem2 copied to clipboard
OSFS.movedir could probably use os.rename
It should be possible to implement OSFS.movedir with an os.rename call, to avoid unnecessary copying.
@willmcgugan I would like to work on this and implement the required functionality
Hi @varunu28 I would be happy to accept a PR!
@varunu28 I'd be happy to test this in my environment. We use Symlinks, SMB shares, and DFS referrals in various places. This means that sometimes a move operation looks like it is within the same filesystem, when in fact it crosses filesystems.
@geoffjukes I'm hoping that in those cases os.rename will fail and we can fall back to the default copy+delete
All the docs say is
The operation may fail on some Unix flavors if src and dst are on different filesystems
I have had os.rename operations act funny across DFS referrals, because the OS sees them as being the same filesystem. Happy to test tho.
@geoffjukes @willmcgugan Can an alternative be to use shutil.move in place of os.rename?
Also correct me if I am wrong, but in both os.rename and shutil.move , I would have to use src_path and dst_path as parameters as they do not take filesystem objects as a parameter?
Hi @varunu28
Sorry for the delay. So shutil.move has the rename functionality, so that should work. Bear in mind it would still need to behave in exactly the way that OSFS.movedir does at the moment (as well as identical exceptions).
Also correct me if I am wrong, but in both os.rename and shutil.move , I would have to use src_path and dst_path as parameters as they do not take filesystem objects as a parameter?
movedir takes FS Paths, you would need to translate those to syspaths, to do the copy.
@willmcgugan Thanks for the clarification. I will go ahead with using shutil
I was just about to report this as an issue, when I saw it already existed ;-) Any progress @varunu28 ?
@willmcgugan Given that https://pyfilesystem2.readthedocs.io/en/latest/reference/base.html#fs.base.FS.move raises an exception if src_path is a directory, should https://pyfilesystem2.readthedocs.io/en/latest/reference/base.html#fs.base.FS.movedir raise an exception if src_path is a file? And should movedir also raise a DestinationExists error?
Hey, was wondering if there was any update on this?
Upgrading from pyfs1, and the new behavior of copy -> delete introduced errors in tests. I've patched it on our side for now, but would be nice to have movedir perform os.rename natively.