Fill stat info when returning cached data for readdir#306
Fill stat info when returning cached data for readdir#306h4sh5 merged 2 commits intolibfuse:masterfrom
Conversation
Uncached and cached results for readdir were inconsistent -- the former returned correct stat info for directory entries while the latter didn't. That's because only names of entries were saved in cache without stat info. In turn this leads to issues like junegunn/fzf#3832 since directory traversal library (https://github.com/charlievieth/fastwalk in this case) relies on proper stat info returned by readdir. Hence when unchached result was returned it gave proper outcome, while with cached result it was wrong. Cache stat info next to entry name to fix the issue. While file attributes are saved in cache already, they use full path as key. To avoid potentially plenty of allocations, string copying and cache lookups to get each attr, let's keep a copy of stat struct independently to be on the fast path.
|
Thank you @jpalus! I think having some test cases for cached stat would be great too, if you don't mind adding some into test/test_sshfs.py in another PR. |
|
@h4sh5 I made an attempt at adding test today but Python's standard library isn't great for raw
So while I've modified scandir_is = os.scandir(mnt_newdir)
scandir_is = sorted(scandir_is, key=operator.attrgetter('name'))
scandir_is2 = os.scandir(mnt_newdir)
scandir_is2 = sorted(scandir_is2, key=operator.attrgetter('name'))
scandir_is = list(map(lambda e: (e.name, e.is_file()), scandir_is))
scandir_is2 = list(map(lambda e: (e.name, e.is_file()), scandir_is2))
scandir_should = [(os.path.basename(file_), True), (os.path.basename(subdir), False)]
scandir_should = sorted(scandir_should, key=operator.itemgetter(0))
assert scandir_is == scandir_should
assert scandir_is2 == scandir_shouldTest passes on revision prior to this change even though it should not. Confirmed with |
|
@jpalus You could try to add tests that run the |
Uncached and cached results for readdir were inconsistent -- the former returned correct stat info for directory entries while the latter didn't. That's because only names of entries were saved in cache without stat info. In turn this leads to issues like
junegunn/fzf#3832 since directory traversal library (https://github.com/charlievieth/fastwalk in this case) relies on proper stat info returned by readdir. Hence when unchached result was returned it gave proper outcome, while with cached result it was wrong.
Cache stat info next to entry name to fix the issue. While file attributes are saved in cache already, they use full path as key. To avoid potentially plenty of allocations, string copying and cache lookups to get each attr, let's keep a copy of stat struct independently to be on the fast path.