Skip to content

Commit

Permalink
Don't touch cache on find with prefix (fsspec#437)
Browse files Browse the repository at this point in the history
* Don't touch cache on find with prefix

* update glob test

Co-authored-by: martindurant <[email protected]>
  • Loading branch information
martindurant and martindurant authored Nov 17, 2021
1 parent 7b5aee9 commit cbf751e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion gcsfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,8 @@ async def _find(self, path, withdirs=False, detail=False, prefix="", **kwargs):
# masking subfiles in subsequent requests.
if not o["name"].endswith("/"):
cache_entries.setdefault(par, []).append(o)
self.dircache.update(cache_entries)
if not prefix:
self.dircache.update(cache_entries)

if withdirs:
out = sorted(out + dirs, key=lambda x: x["name"])
Expand Down
7 changes: 5 additions & 2 deletions gcsfs/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@ def test_gcs_glob(gcs):
gcs.dircache.clear()
gcs.glob(TEST_BUCKET + "/nested**1")
assert all(d.startswith(TEST_BUCKET + "/nested") for d in gcs.dircache)
gcs.glob(TEST_BUCKET + "/test*")
assert TEST_BUCKET + "/test" in gcs.dircache
# the following is no longer true as of #437
# gcs.glob(TEST_BUCKET + "/test*")
# assert TEST_BUCKET + "/test" in gcs.dircache


def test_read_keys_from_bucket(gcs):
Expand Down Expand Up @@ -953,11 +954,13 @@ def test_find_with_prefix_partial_cache(gcs):
gcs.invalidate_cache()
if with_cache:
gcs.ls(base_dir)
precache = dict(gcs.dircache)
assert gcs.find(base_dir, prefix="non_existent_") == []
assert gcs.find(base_dir, prefix="test_") == [
base_dir + "/test_1",
base_dir + "/test_2",
]
assert dict(gcs.dircache) == precache # find qwith prefix shouldn't touch cache
assert gcs.find(base_dir + "/test_1") == [base_dir + "/test_1"]
assert gcs.find(base_dir + "/non_existent") == []
assert gcs.find(base_dir + "/non_existent", prefix="more_non_existent") == []
Expand Down

0 comments on commit cbf751e

Please sign in to comment.