Hi,
while experimenting with the FS lib, I’ve encountered an unexpected ResourceNotFound error. The error is raised if the param preserve_time=True and we try to move a file on the same OS or in-memory filesystem.
This block represents a reproduceable example for a MemoryFS:
mem_fs = memoryfs.MemoryFS()
mem_fs.makedir("foo")
mem_fs.writetext("foo/README.md", "Tetris clone")
move_file(
src_fs=mem_fs,
src_path="foo/README.md",
dst_fs=mem_fs,
dst_path="foo/README_2.md",
preserve_time=True,
)
The raised error message:
./tests/test_resource_error.py::test_move_between_same_fs_mem Failed: [undefined]fs.errors.ResourceNotFound: resource 'foo/README.md' not found
def test_move_between_same_fs_mem():
mem_fs = memoryfs.MemoryFS()
mem_fs.makedir("foo")
mem_fs.writetext("foo/README.md", "Tetris clone")
> move_file(
src_fs=mem_fs,
src_path="foo/README.md",
dst_fs=mem_fs,
dst_path="foo/README_2.md",
preserve_time=True,
)
tests\test_resource_error.py:31:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
fs\move.py:68: in move_file
_src_fs.move(
fs\memoryfs.py:478: in move
copy_modified_time(self, src_path, self, dst_path)
fs\copy.py:532: in copy_modified_time
src_meta = _src_fs.getinfo(src_path, namespaces)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = MemoryFS(), path = 'foo/README.md', namespaces = ('details',)
def getinfo(self, path, namespaces=None):
# type: (Text, Optional[Collection[Text]]) -> Info
_path = self.validatepath(path)
dir_entry = self._get_dir_entry(_path)
if dir_entry is None:
> raise errors.ResourceNotFound(path)
E fs.errors.ResourceNotFound: resource 'foo/README.md' not found
fs\memoryfs.py:394: ResourceNotFound
I have modified the test case test_move_file_same_fs and found similar errors for OS- and Temp-filesystems. For my understanding, the current implementation wants to copy the file’s metadata, after moving it or renaming its path. Therefore, the copy_modified_time function encounters a missing resource under these conditions:
- moving a file on the same filesystem
- preserve_time=True
AND either
-
copy_modified_time is called after moving the file, see memoryfs.py
-
or FS.move of base.py is used and the filesystem supports renaming, see base.py
Is this a limitation of my system (Win11 x64)?
I could not find similar issues or information in the docs.
If this is a not yet supported edge case, I would suggest that we read the file’s meta data first, then move it and update the meta info afterwards.
Any review and comments are welcome!
Regards
Hi,
while experimenting with the FS lib, I’ve encountered an unexpected
ResourceNotFounderror. The error is raised if the parampreserve_time=Trueand we try to move a file on the same OS or in-memory filesystem.This block represents a reproduceable example for a MemoryFS:
The raised error message:
I have modified the test case
test_move_file_same_fsand found similar errors for OS- and Temp-filesystems. For my understanding, the current implementation wants to copy the file’s metadata, after moving it or renaming its path. Therefore, thecopy_modified_timefunction encounters a missing resource under these conditions:AND either
copy_modified_timeis called after moving the file, see memoryfs.pyor FS.move of base.py is used and the filesystem supports renaming, see base.py
Is this a limitation of my system (Win11 x64)?
I could not find similar issues or information in the docs.
If this is a not yet supported edge case, I would suggest that we read the file’s meta data first, then move it and update the meta info afterwards.
Any review and comments are welcome!
Regards