Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
22 changes: 12 additions & 10 deletions gcsfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1902,29 +1902,31 @@ def _get_dirs_and_update_cache(self, path, objects, prefix="", update_cache=True

while parent:
dir_key = self.split_path(parent)[1]
if not dir_key or len(parent) < len(path.rstrip("/")):
if len(parent) < len(path.rstrip("/")):
break

if prefix and not parent.startswith(full_prefix):
# If this parent doesn't match the prefix, neither will its parents.
break

dirs[parent] = {
"Key": dir_key,
"Size": 0,
"name": parent,
"StorageClass": "DIRECTORY",
"type": "directory",
"size": 0,
}
if dir_key:
dirs[parent] = {
"Key": dir_key,
"Size": 0,
"name": parent,
"StorageClass": "DIRECTORY",
"type": "directory",
"size": 0,
}

if not prefix and update_cache:
listing = cache_entries.setdefault(parent, {})
name = previous["name"]
if name not in listing:
listing[name] = previous

previous = dirs[parent]
if parent in dirs:
previous = dirs[parent]
parent = self._parent(parent)
if not prefix and update_cache:
cache_entries_list = {k: list(v.values()) for k, v in cache_entries.items()}
Expand Down
15 changes: 15 additions & 0 deletions gcsfs/tests/integration/test_extended_hns.py
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,21 @@ def test_find_updates_dircache_without_prefix(
}
assert not empty_dir_listing

@pytest.mark.parametrize("withdirs_param", [True, False])
def test_find_updates_dircache_for_root_bucket(
self, gcs_hns, test_structure, withdirs_param
):
"""Test that find() populates the dircache for the root bucket itself."""
root_bucket = TEST_HNS_BUCKET
gcs_hns.invalidate_cache()
assert not gcs_hns.dircache

# Run find on the root bucket to populate the cache
gcs_hns.find(root_bucket, withdirs=withdirs_param)

# Verify that the cache is now populated for the root bucket
assert root_bucket in gcs_hns.dircache
Comment thread
yuxin00j marked this conversation as resolved.
Comment thread
yuxin00j marked this conversation as resolved.

def test_find_maxdepth_updates_cache(self, gcs_hns, test_structure):
"""Test that find with maxdepth updates cache for deeper objects."""
base_dir = test_structure["base_dir"]
Expand Down
22 changes: 11 additions & 11 deletions gcsfs/tests/test_core.py
Comment thread
yuxin00j marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -1946,10 +1946,10 @@ def test_attrs(gcs):
assert gcs.getxattr(a, "something") == "not"


def test_request_user_project(gcs_factory):
gcs = gcs_factory(requester_pays=True, project=TEST_PROJECT)
def test_request_user_project(gcs, gcs_factory):
gcs_inst = gcs_factory(requester_pays=True, project=TEST_PROJECT)
# test directly against `_call` to inspect the result
r = gcs.call(
r = gcs_inst.call(
"GET",
"b/{}/o",
TEST_BUCKET,
Expand All @@ -1963,11 +1963,11 @@ def test_request_user_project(gcs_factory):
assert result["userProject"] == [TEST_PROJECT]


def test_request_user_project_string(gcs_factory):
gcs = gcs_factory(requester_pays=TEST_PROJECT)
assert gcs.requester_pays == TEST_PROJECT
def test_request_user_project_string(gcs, gcs_factory):
gcs_inst = gcs_factory(requester_pays=TEST_PROJECT)
assert gcs_inst.requester_pays == TEST_PROJECT
# test directly against `_call` to inspect the result
r = gcs.call(
r = gcs_inst.call(
"GET",
"b/{}/o",
TEST_BUCKET,
Expand All @@ -1981,10 +1981,10 @@ def test_request_user_project_string(gcs_factory):
assert result["userProject"] == [TEST_PROJECT]


def test_request_header(gcs_factory):
gcs = gcs_factory(requester_pays=True)
def test_request_header(gcs, gcs_factory):
gcs_inst = gcs_factory(requester_pays=True)
# test directly against `_call` to inspect the result
r = gcs.call(
r = gcs_inst.call(
"GET",
"b/{}/o",
TEST_BUCKET,
Expand Down Expand Up @@ -2025,7 +2025,7 @@ def test_requester_pays_fails_without_user_project(requester_pays_bucket, gcs_fa
fs.ls(requester_pays_bucket)


def test_fs_requester_pays_on_bucket_without_requester_pays(gcs_factory):
def test_fs_requester_pays_on_bucket_without_requester_pays(gcs, gcs_factory):
"""Test that metadata and data operations work when fs has requester_pays=True
but the bucket does not have requester-pays enabled."""
fs = gcs_factory(requester_pays=True)
Expand Down
Loading