Skip to content

Commit

Permalink
Restore original iterator for non-lazy load
Browse files Browse the repository at this point in the history
The modified iterator causes failure of FileSystem.tree() and copy_dir()
APIs which become apparent when opening a new filesystem and comparing
the directory tree
  • Loading branch information
zurcher authored and nathanhi committed Jul 9, 2023
1 parent c8b4f30 commit 4f8bfd5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/8051Enthusiast/regex2fat>`_ compatibility
- Introduce ``lazy_load`` parameter to allow restoring previous behavior
- `PR #32 <https://github.com/nathanhi/pyfatfs/pull/32>`_: Fix tree iteration on non-lazy load by `@zurcher <https://github.com/zurcher>`_ / `@Microsoft <https://github.com/Microsoft>`_

1.0.5_ - 2022-04-16
-------------------
Expand Down
4 changes: 3 additions & 1 deletion pyfatfs/PyFat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions tests/test_PyFatFS.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 4f8bfd5

Please sign in to comment.