Skip to content
Open
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
5 changes: 4 additions & 1 deletion s3fs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,10 @@ async def _find(
# Explicitly add directories to their parents in the dircache
for d in dirs:
par = self._parent(d["name"])
if par in thisdircache:
# extra condition here (in any()) to deal with director-marking files
if par in thisdircache and not any(
_["name"] == d["name"] for _ in thisdircache[par]
):
thisdircache[par].append(d)

if not prefix:
Expand Down
25 changes: 25 additions & 0 deletions s3fs/tests/test_s3fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2993,3 +2993,28 @@ def test_bucket_info(s3):
assert "VersionId" in info
assert info["type"] == "directory"
assert info["name"] == test_bucket_name


def test_find_ls_fail(s3):
# beacuse of https://github.com/fsspec/s3fs/pull/989
client = get_boto3_client()
files = {
f"{test_bucket_name}/find/a/a": b"data",
f"{test_bucket_name}/find/a/b": b"data",
f"{test_bucket_name}/find/a": b"", # placeholder without "/"
f"{test_bucket_name}/find/b": b"", # empty placeholder without "/"
f"{test_bucket_name}/find/c/c": b"data", # directory with no placeholder
f"{test_bucket_name}/find/d/d": b"data", # dir will acquire placeholder with "/"
}
client.put_object(Bucket=test_bucket_name, Key="find/d/", Body=b"")
s3.pipe(files)

out0 = s3.ls(f"{test_bucket_name}/find", detail=True)
s3.find(test_bucket_name, detail=False)
out = s3.ls(f"{test_bucket_name}/find", detail=True)
assert out == out0

s3.invalidate_cache()
s3.find(f"{test_bucket_name}/find", detail=False)
out = s3.ls(f"{test_bucket_name}/find", detail=True)
assert out == out0
Loading