Skip to content

Commit

Permalink
Fix find after find (#730)
Browse files Browse the repository at this point in the history
  • Loading branch information
martindurant committed Apr 25, 2023
1 parent a7455f9 commit 9954eea
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
37 changes: 18 additions & 19 deletions s3fs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,25 +820,24 @@ async def _find(self, path, maxdepth=None, withdirs=None, detail=False, prefix="
thisdircache = {}
for o in out:
par = self._parent(o["name"])
if par not in self.dircache:
if par not in sdirs:
sdirs.add(par)
d = False
if len(path) <= len(par):
d = {
"Key": self.split_path(par)[1],
"Size": 0,
"name": par,
"StorageClass": "DIRECTORY",
"type": "directory",
"size": 0,
}
dirs.append(d)
thisdircache[par] = []
ppar = self._parent(par)
if ppar in thisdircache:
if d and d not in thisdircache[ppar]:
thisdircache[ppar].append(d)
if par not in sdirs:
sdirs.add(par)
d = False
if len(path) <= len(par):
d = {
"Key": self.split_path(par)[1],
"Size": 0,
"name": par,
"StorageClass": "DIRECTORY",
"type": "directory",
"size": 0,
}
dirs.append(d)
thisdircache[par] = []
ppar = self._parent(par)
if ppar in thisdircache:
if d and d not in thisdircache[ppar]:
thisdircache[ppar].append(d)
if par in sdirs:
thisdircache[par].append(o)
if not prefix:
Expand Down
23 changes: 23 additions & 0 deletions s3fs/tests/test_s3fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2147,6 +2147,29 @@ def test_shallow_find(s3):
assert s3.ls(test_bucket_name) == s3.glob(test_bucket_name + "/*")


def test_multi_find(s3):
s3.mkdir("bucket/test")
s3.mkdir("bucket/test/sub")
s3.write_text("bucket/test/file.txt", "some_text")
s3.write_text("bucket/test/sub/file.txt", "some_text")

out1 = s3.find("bucket", withdirs=True)
out2 = s3.find("bucket", withdirs=True)
assert (
out1
== out2
== [
"bucket/test",
"bucket/test/file.txt",
"bucket/test/sub",
"bucket/test/sub/file.txt",
]
)
out1 = s3.find("bucket", withdirs=False)
out2 = s3.find("bucket", withdirs=False)
assert out1 == out2 == ["bucket/test/file.txt", "bucket/test/sub/file.txt"]


def test_version_sizes(s3):
# protect against caching of incorrect version details
s3 = S3FileSystem(
Expand Down

0 comments on commit 9954eea

Please sign in to comment.