Skip to content

Commit 540a6f7

Browse files
authored
Merge pull request #676 from skshetry/find-less-isfile-calls
avoid isfile calls on find as much as possible
2 parents a84d7fe + 1e85844 commit 540a6f7

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

fsspec/asyn.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ async def _find(self, path, maxdepth=None, withdirs=False, **kwargs):
581581
if withdirs:
582582
files.update(dirs)
583583
out.update({info["name"]: info for name, info in files.items()})
584-
if (await self._isfile(path)) and path not in out:
584+
if not out and (await self._isfile(path)):
585585
# walk works on directories, but find should also return [path]
586586
# when path happens to be a file
587587
out[path] = {}

fsspec/spec.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ def find(self, path, maxdepth=None, withdirs=False, **kwargs):
445445
if withdirs:
446446
files.update(dirs)
447447
out.update({info["name"]: info for name, info in files.items()})
448-
if self.isfile(path) and path not in out:
448+
if not out and self.isfile(path):
449449
# walk works on directories, but find should also return [path]
450450
# when path happens to be a file
451451
out[path] = {}

fsspec/tests/test_spec.py

+8
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,14 @@ def test_find_details():
232232
assert details[filename] == test_fs.info(filename)
233233

234234

235+
def test_find_file():
236+
test_fs = DummyTestFS()
237+
238+
filename = "misc/foo.txt"
239+
assert test_fs.find(filename) == [filename]
240+
assert test_fs.find(filename, detail=True) == {filename: {}}
241+
242+
235243
def test_cache():
236244
fs = DummyTestFS()
237245
fs2 = DummyTestFS()

0 commit comments

Comments
 (0)