Skip to content

Commit

Permalink
feat: avoid calling isdir before fetching objects
Browse files Browse the repository at this point in the history
  • Loading branch information
john-jam committed Aug 30, 2023
1 parent 13a6ac6 commit d1ff25f
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions gcsfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1387,24 +1387,27 @@ async def _find(
**kwargs,
):
path = self._strip_protocol(path)
bucket, key, generation = self.split_path(path)

if maxdepth is not None and maxdepth < 1:
raise ValueError("maxdepth must be at least 1")

if prefix:
_path = "" if not key else key.rstrip("/") + "/"
_prefix = f"{_path}{prefix}"
else:
_prefix = key

if _prefix != "" and await self._isdir(f"{bucket}/{_prefix}"):
_prefix = _prefix.rstrip("/") + "/"

# Fetch objects as if the path is a directory
objects, _ = await self._do_list_objects(
bucket, delimiter="", prefix=_prefix, versions=versions
path, delimiter="", prefix=prefix, versions=versions
)

if not objects:
# Fetch objects as if the path is a file
bucket, key, _ = self.split_path(path)
if prefix:
_path = "" if not key else key.rstrip("/") + "/"
_prefix = f"{_path}{prefix}"
else:
_prefix = key
objects, _ = await self._do_list_objects(
bucket, delimiter="", prefix=_prefix, versions=versions
)

dirs = {}
cache_entries = {}

Expand Down

0 comments on commit d1ff25f

Please sign in to comment.