Skip to content

Commit

Permalink
Merge pull request #274 from ozkatz/fix/exists-on-directory
Browse files Browse the repository at this point in the history
fs.exists() should return True for common prefixes
  • Loading branch information
nicholasjng authored Mar 31, 2024
2 parents 7a82c7b + 916d912 commit d75c5b2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lakefs_spec/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,13 @@ def exists(self, path: str | os.PathLike[str], **kwargs: Any) -> bool:
repository, ref, resource = parse(path)
try:
reference = lakefs.Reference(repository, ref, client=self.client)
return reference.object(resource).exists()
if reference.object(resource).exists():
return True
# if it isn't an object, it might be a common prefix (i.e. "directory").
children = reference.objects(
max_amount=1, prefix=resource.rstrip("/") + "/", delimiter="/"
)
return len(list(children)) > 0
except ServerException as e:
# in case of an error other than "not found", existence cannot be
# decided, so raise the translated error.
Expand Down

0 comments on commit d75c5b2

Please sign in to comment.