From 47f9cfd66232e6de2c0a997a3cf26962fc303040 Mon Sep 17 00:00:00 2001 From: Martin Larralde Date: Mon, 13 Dec 2021 16:18:58 +0100 Subject: [PATCH 1/5] Add missing `UnsupportedHash` exception to `fs.errors.__all__` --- fs/errors.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/errors.py b/fs/errors.py index 2448c7a6..ba193bdb 100644 --- a/fs/errors.py +++ b/fs/errors.py @@ -51,6 +51,7 @@ "ResourceNotFound", "ResourceReadOnly", "Unsupported", + "UnsupportedHash", ] From fee7ee60b86cdb41be47d2f801d84ccaedfca95e Mon Sep 17 00:00:00 2001 From: Martin Larralde Date: Mon, 13 Dec 2021 17:27:11 +0100 Subject: [PATCH 2/5] Update `fs.test` to make sure that files moved in the same FS get renamed --- fs/test.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/fs/test.py b/fs/test.py index 3e08f4ff..7be3f397 100644 --- a/fs/test.py +++ b/fs/test.py @@ -1738,6 +1738,22 @@ def test_copy_dir_temp(self): self._test_copy_dir("temp://") self._test_copy_dir_write("temp://") + def test_move_dir_same_fs(self): + self.fs.makedirs("foo/bar/baz") + self.fs.makedir("egg") + self.fs.writetext("top.txt", "Hello, World") + self.fs.writetext("/foo/bar/baz/test.txt", "Goodbye, World") + + fs.move.move_dir(self.fs, "foo", self.fs, "foo2") + + expected = {"/egg", "/foo2", "/foo2/bar", "/foo2/bar/baz"} + self.assertEqual(set(walk.walk_dirs(self.fs)), expected) + self.assert_text("top.txt", "Hello, World") + self.assert_text("/foo2/bar/baz/test.txt", "Goodbye, World") + + self.assertEqual(sorted(self.fs.listdir("/")), ["egg", "foo2", "top.txt"]) + self.assertEqual(sorted(x.name for x in self.fs.scandir("/")), ["egg", "foo2", "top.txt"]) + def _test_move_dir_write(self, protocol): # Test moving to this filesystem from another. other_fs = open_fs(protocol) @@ -1760,19 +1776,6 @@ def test_move_dir_mem(self): def test_move_dir_temp(self): self._test_move_dir_write("temp://") - def test_move_same_fs(self): - self.fs.makedirs("foo/bar/baz") - self.fs.makedir("egg") - self.fs.writetext("top.txt", "Hello, World") - self.fs.writetext("/foo/bar/baz/test.txt", "Goodbye, World") - - fs.move.move_dir(self.fs, "foo", self.fs, "foo2") - - expected = {"/egg", "/foo2", "/foo2/bar", "/foo2/bar/baz"} - self.assertEqual(set(walk.walk_dirs(self.fs)), expected) - self.assert_text("top.txt", "Hello, World") - self.assert_text("/foo2/bar/baz/test.txt", "Goodbye, World") - def test_move_file_same_fs(self): text = "Hello, World" self.fs.makedir("foo").writetext("test.txt", text) @@ -1782,6 +1785,9 @@ def test_move_file_same_fs(self): self.assert_not_exists("foo/test.txt") self.assert_text("foo/test2.txt", text) + self.assertEqual(self.fs.listdir("foo"), ["test2.txt"]) + self.assertEqual(next(self.fs.scandir("foo")).name, "test2.txt") + def _test_move_file(self, protocol): other_fs = open_fs(protocol) From 13f1c293a7c579dad31011440b9e986b0148397f Mon Sep 17 00:00:00 2001 From: Martin Larralde Date: Mon, 13 Dec 2021 17:45:19 +0100 Subject: [PATCH 3/5] Fix `MemoryFS` entries not being renamed when moved --- fs/memoryfs.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/memoryfs.py b/fs/memoryfs.py index c34d60a7..35ef0f51 100644 --- a/fs/memoryfs.py +++ b/fs/memoryfs.py @@ -463,8 +463,11 @@ def move(self, src_path, dst_path, overwrite=False, preserve_time=False): elif not overwrite and dst_name in dst_dir_entry: raise errors.DestinationExists(dst_path) + # move the entry from the src folder to the dst folder dst_dir_entry.set_entry(dst_name, src_entry) src_dir_entry.remove_entry(src_name) + # make sure to update the entry name itself (see #509) + src_entry.name = dst_name if preserve_time: copy_modified_time(self, src_path, self, dst_path) @@ -481,12 +484,16 @@ def movedir(self, src_path, dst_path, create=False, preserve_time=False): if not src_entry.is_dir: raise errors.DirectoryExpected(src_path) + # move the entry from the src folder to the dst folder dst_dir_entry = self._get_dir_entry(dst_dir) if dst_dir_entry is None or (not create and dst_name not in dst_dir_entry): raise errors.ResourceNotFound(dst_path) + # move the entry from the src folder to the dst folder dst_dir_entry.set_entry(dst_name, src_entry) src_dir_entry.remove_entry(src_name) + # make sure to update the entry name itself (see #509) + src_entry.name = dst_name if preserve_time: copy_modified_time(self, src_path, self, dst_path) From c29a917fac30aa3842be49a6f83bac319f863c6a Mon Sep 17 00:00:00 2001 From: Martin Larralde Date: Mon, 13 Dec 2021 17:56:08 +0100 Subject: [PATCH 4/5] Reformat code of `fs.test` module with `black` --- fs/test.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/test.py b/fs/test.py index 7be3f397..0327f98d 100644 --- a/fs/test.py +++ b/fs/test.py @@ -1752,7 +1752,9 @@ def test_move_dir_same_fs(self): self.assert_text("/foo2/bar/baz/test.txt", "Goodbye, World") self.assertEqual(sorted(self.fs.listdir("/")), ["egg", "foo2", "top.txt"]) - self.assertEqual(sorted(x.name for x in self.fs.scandir("/")), ["egg", "foo2", "top.txt"]) + self.assertEqual( + sorted(x.name for x in self.fs.scandir("/")), ["egg", "foo2", "top.txt"] + ) def _test_move_dir_write(self, protocol): # Test moving to this filesystem from another. From d76e7f3818a85577e7b21884404a8850177d67a5 Mon Sep 17 00:00:00 2001 From: Martin Larralde Date: Mon, 13 Dec 2021 18:14:00 +0100 Subject: [PATCH 5/5] Update `CHANGELOG.md` with changes from #510 --- CHANGELOG.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dab094b1..ab0d827c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,19 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased -- Support more leniant usernames and group names in FTP servers [#507](https://github.com/PyFilesystem/pyfilesystem2/pull/507). Closes [#506](https://github.com/PyFilesystem/pyfilesystem2/pull/506). +### Changed + +- Support more lenient usernames and group names in FTP servers + ([#507](https://github.com/PyFilesystem/pyfilesystem2/pull/507)). + Closes [#506](https://github.com/PyFilesystem/pyfilesystem2/issues/506). + +### Fixed + +- Fixed `MemoryFS.move` and `MemoryFS.movedir` not updating the name of moved + resources, causing `MemoryFS.scandir` to use the old name. + ([#510](https://github.com/PyFilesystem/pyfilesystem2/pull/510)). + Closes [#509](https://github.com/PyFilesystem/pyfilesystem2/issues/509). + ## [2.4.14] - 2021-11-16