You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
File is deleted / empty when moved / copied onto itself #546
This happens in both fs.base.FS.move and fs.move.move_file.
Due to the optimization in #523 this does not happen on OSFS, but applies to other filesystems with shared connections. For example when moving a file from one connection to a ftp server onto itself in another connection to the same ftp server.
For a solution a function is needed to check whether two different (fs, path) tuples point to the same resource.
check whether two different (fs, path) tuples point to the same resource
I'm not sure there's any reasonable way that that can be done consistently for different fs objects? 🤔 So it should be possible to fix it for fs.base.FS.move, but I dunno it it'll be possible to fix it for fs.move.move_file ?
I'm not sure there's any reasonable way that that can be done consistently for different fs objects? 🤔 So it should be possible to fix it for fs.base.FS.move, but I dunno it it'll be possible to fix it for fs.move.move_file ?
The move method needs to be patched in multiple places. I'll create a draft PR for this.
For move_file I'd try to compare syspaths first, urls second and then try to find out whether we are on the same filesystem and compare normalized abspaths (paying attention to fs case-sensitivity). Please have a look at the changes I made in #519, these would be really helpful (although using __eq__ might not be the way to go).
Your second example works fine by the way, because you have two separate filesystems.
Your second example works fine by the way, because you have two separate filesystems.
Yes, that's what I was illustrating - the second example "works fine" and the first example "doesn't work"; but as far as the move_file function is concerned, the two function-calls "look" identical:
Activity
lurch commentedon Jul 21, 2022
I'm not sure there's any reasonable way that that can be done consistently for different
fsobjects? 🤔 So it should be possible to fix it forfs.base.FS.move, but I dunno it it'll be possible to fix it forfs.move.move_file?I guess something like
might also trigger this "erroneous behaviour"?
As far as the
move_filefunction is concerned, I guess it can't differentiate the above from🤔 🤷♂️
Although I guess at least for the FTP case (i.e. where we can't get a syspath), you could try getting the download URL https://docs.pyfilesystem.org/en/latest/reference/base.html#fs.base.FS.geturl and use that as an attempt to see if two different
(fs, path)tuples match to the same resource?tfeldmann commentedon Jul 22, 2022
The
movemethod needs to be patched in multiple places. I'll create a draft PR for this.For
move_fileI'd try to compare syspaths first, urls second and then try to find out whether we are on the same filesystem and compare normalized abspaths (paying attention to fs case-sensitivity). Please have a look at the changes I made in #519, these would be really helpful (although using__eq__might not be the way to go).Your second example works fine by the way, because you have two separate filesystems.
lurch commentedon Jul 22, 2022
Yes, that's what I was illustrating - the second example "works fine" and the first example "doesn't work"; but as far as the
move_filefunction is concerned, the two function-calls "look" identical:tfeldmann commentedon Jul 22, 2022
Ah I see, didn't think about that!
So some additional checks are needed when encountering a SubFS? (compare to
subdir.delegate_fs()andsubdir.delegate_path(path))tfeldmann commentedon Jul 22, 2022
copyhas kind of the same problem, but leaves an empty file:[-]File is deleted when moved onto itself[/-][+]File is deleted / empty when moved / copied onto itself[/+]lurch commentedon Jul 22, 2022
Do similar problems also occur when trying to move or copy directories onto themselves?
tfeldmann commentedon Jul 22, 2022
Yep.
move_dirdeletes the folder.copydirhangs forever:tfeldmann commentedon Jul 22, 2022
Moving a folder into a subfolder of itself is also not a good idea at the moment. This should raise an exception.
lurch commentedon Jul 22, 2022
It hangs forever (gets stuck in an infinite loop) if you try copying a folder into a subfolder of itself, but if you do:
then the files get truncated to being empty again.
tfeldmann commentedon Jul 22, 2022
Seems like this
mem.copydir("folder", "folder")is accidentally already repaired in my PR #547Merge pull request #547 from tfeldmann/fix/file-deleted-when-moved-on…