diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 62b2c15..9d5c57b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -21,6 +21,7 @@ Changed * Discard unknown PyFilesystem2 opener arguments, do not pass through to underlying PyFatFS constructor * Lazy load directory entries for performance and `regex2fat `_ compatibility - Introduce ``lazy_load`` parameter to allow restoring previous behavior + - `PR #32 `_: Fix tree iteration on non-lazy load by `@zurcher `_ / `@Microsoft `_ 1.0.5_ - 2022-04-16 ------------------- diff --git a/pyfatfs/PyFat.py b/pyfatfs/PyFat.py index b55b7ff..87da38a 100755 --- a/pyfatfs/PyFat.py +++ b/pyfatfs/PyFat.py @@ -761,7 +761,9 @@ def parse_dir_entries_in_address(self, if not self.lazy_load: if dir_entry.is_directory() and not dir_entry.is_special(): # Iterate all subdirectories except for dot and dotdot - for d in dir_entry.get_entries()[0]: + cluster = dir_entry.get_cluster() + subdirs = self.parse_dir_entries_in_cluster_chain(cluster) + for d in subdirs: dir_entry.add_subdirectory(d) # Reset temporary LFN entry diff --git a/tests/test_PyFatFS.py b/tests/test_PyFatFS.py index ddb9b61..a62d307 100644 --- a/tests/test_PyFatFS.py +++ b/tests/test_PyFatFS.py @@ -59,11 +59,18 @@ def test_lazy_vs_nonlazy_tree(self): fs1.touch(os.path.join(d, "This requires an LFN entry.TxT")) fs1.touch(os.path.join(d, "FILE2.TXT")) - dentries = list(fs1.walk("/")) + dentries_fs1_initial = list(fs1.walk("/")) + fs1.fs.flush_fat() + in_memory_fs.seek(0) + in_memory_fs = BytesIO(in_memory_fs.read()) + fs1 = PyFatBytesIOFS(in_memory_fs, encoding='UTF-8', lazy_load=False) + dentries_fs1_reopen = list(fs1.walk("/")) + assert dentries_fs1_initial == dentries_fs1_reopen + in_memory_fs.seek(0) fs2 = PyFatBytesIOFS(BytesIO(in_memory_fs.read()), encoding='UTF-8', lazy_load=True) - assert dentries == list(fs2.walk("/")) + assert dentries_fs1_reopen == list(fs2.walk("/")) fs1.close() fs2.close()