Skip to content

Commit b0e89c0

Browse files
authored
Fix find with path not ending with "/" (#668)
1 parent 72100db commit b0e89c0

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Diff for: gcsfs/core.py

+7
Original file line numberDiff line numberDiff line change
@@ -1519,10 +1519,17 @@ async def _find(
15191519
objects, _ = await self._do_list_objects(
15201520
bucket, delimiter="", prefix=_prefix, versions=versions
15211521
)
1522+
else:
1523+
_prefix = prefix
15221524

15231525
dirs = {}
15241526
cache_entries = {}
1527+
path2 = path.rstrip("/") + "/"
15251528

1529+
if not prefix:
1530+
objects = [
1531+
o for o in objects if o["name"].startswith(path2) or o["name"] == path
1532+
]
15261533
for obj in objects:
15271534
parent = self._parent(obj["name"])
15281535
previous = obj

Diff for: gcsfs/tests/test_core.py

+6
Original file line numberDiff line numberDiff line change
@@ -1574,3 +1574,9 @@ def test_write_x_mpu(gcs):
15741574
with gcs.open(fn, mode="xb", block_size=5 * 2**20) as f:
15751575
f.write(b"0" * 5 * 2**20)
15761576
f.write(b"done")
1577+
1578+
1579+
def test_near_find(gcs):
1580+
gcs.touch(f"{TEST_BUCKET}/inner/aa/file")
1581+
out = gcs.find(f"{TEST_BUCKET}/inner/a")
1582+
assert not out

0 commit comments

Comments
 (0)