Skip to content

Commit

Permalink
added refresh flag to ls
Browse files Browse the repository at this point in the history
  • Loading branch information
SchadtJ committed May 30, 2023
1 parent 7e19252 commit 5d60e22
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gcsfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,10 +835,12 @@ async def _glob(self, path, prefix="", **kwargs):
prefix = path[:ind].split("/")[-1]
return await super()._glob(path, prefix=prefix, **kwargs)

async def _ls(self, path, detail=False, prefix="", versions=False, **kwargs):
async def _ls(self, path, detail=False, refresh=False, prefix="", versions=False, **kwargs):
"""List objects under the given '/{bucket}/{prefix} path."""
path = self._strip_protocol(path).rstrip("/")

if refresh:
self.invalidate_cache()
if path in ["/", ""]:
out = await self._list_buckets()
else:
Expand Down
5 changes: 5 additions & 0 deletions gcsfs/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ def test_ls_detail(gcs):
L = gcs.ls(TEST_BUCKET + "/nested", detail=True)
assert all(isinstance(item, dict) for item in L)

@pytest.mark.parametrize("refresh", (False, True))
def test_ls_refresh(gcs, refresh):
with mock.patch.object(gcs, "invalidate_cache") as mock_invalidate_cache:
gcs.ls(TEST_BUCKET, refresh=refresh)
assert mock_invalidate_cache.called is refresh

def test_gcs_glob(gcs):
fn = TEST_BUCKET + "/nested/file1"
Expand Down

0 comments on commit 5d60e22

Please sign in to comment.