Skip to content

Commit

Permalink
added refresh flag to ls (#556)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Martin Durant <[email protected]>
Co-authored-by: Martin Durant <[email protected]>
  • Loading branch information
3 people committed Aug 24, 2023
1 parent 54eaa80 commit ad32812
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gcsfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,10 +1001,14 @@ 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, prefix="", versions=False, refresh=False, **kwargs
):
"""List objects under the given '/{bucket}/{prefix} path."""
path = self._strip_protocol(path).rstrip("/")

if refresh:
self.invalidate_cache(path)
if path in ["/", ""]:
out = await self._list_buckets()
else:
Expand Down
7 changes: 7 additions & 0 deletions gcsfs/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ def test_ls_detail(gcs):
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"
assert fn not in gcs.glob(TEST_BUCKET + "/")
Expand Down

0 comments on commit ad32812

Please sign in to comment.