Skip to content

Commit

Permalink
Merge pull request #676 from skshetry/find-less-isfile-calls
Browse files Browse the repository at this point in the history
avoid isfile calls on find as much as possible
  • Loading branch information
martindurant authored Jun 21, 2021
2 parents a84d7fe + 1e85844 commit 540a6f7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fsspec/asyn.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ async def _find(self, path, maxdepth=None, withdirs=False, **kwargs):
if withdirs:
files.update(dirs)
out.update({info["name"]: info for name, info in files.items()})
if (await self._isfile(path)) and path not in out:
if not out and (await self._isfile(path)):
# walk works on directories, but find should also return [path]
# when path happens to be a file
out[path] = {}
Expand Down
2 changes: 1 addition & 1 deletion fsspec/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def find(self, path, maxdepth=None, withdirs=False, **kwargs):
if withdirs:
files.update(dirs)
out.update({info["name"]: info for name, info in files.items()})
if self.isfile(path) and path not in out:
if not out and self.isfile(path):
# walk works on directories, but find should also return [path]
# when path happens to be a file
out[path] = {}
Expand Down
8 changes: 8 additions & 0 deletions fsspec/tests/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ def test_find_details():
assert details[filename] == test_fs.info(filename)


def test_find_file():
test_fs = DummyTestFS()

filename = "misc/foo.txt"
assert test_fs.find(filename) == [filename]
assert test_fs.find(filename, detail=True) == {filename: {}}


def test_cache():
fs = DummyTestFS()
fs2 = DummyTestFS()
Expand Down

0 comments on commit 540a6f7

Please sign in to comment.