Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalidate dircache on copy #564

Merged
merged 1 commit into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gcsfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,7 @@ async def _cp_file(self, path1, path2, acl=None, **kwargs):
json_out=True,
sourceGeneration=g1,
)
self.invalidate_cache(self._parent(path2))

async def _rm_file(self, path, **kwargs):
bucket, key, generation = self.split_path(path)
Expand Down
21 changes: 21 additions & 0 deletions gcsfs/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1374,3 +1374,24 @@ def test_expiry_keyword():
assert gcs.dircache.listings_expiry_time == 1
gcs = GCSFileSystem(cache_timeout=1, token="anon")
assert gcs.dircache.listings_expiry_time == 1


def test_copy_cache_invalidated(gcs):
# Issue https://github.com/fsspec/gcsfs/issues/562
source = TEST_BUCKET + "/source"
gcs.mkdir(source)
gcs.touch(source + "/file2")

target = TEST_BUCKET + "/target"
assert not gcs.exists(target)
gcs.touch(target + "/dummy")
assert gcs.isdir(target)

target_file2 = target + "/file2"
gcs.cp(source + "/file2", target)

# Explicitly check that target has been removed from DirCache
assert target not in gcs.dircache

# Prior to fix the following failed as cache stale
assert gcs.isfile(target_file2)
Loading