Skip to content

Commit

Permalink
Fix schemeless.isdir
Browse files Browse the repository at this point in the history
Previously it had not been modified to understand forceDirectory=None.
Also, we do not cache the result if the resource is not present.
  • Loading branch information
timj committed Jan 16, 2024
1 parent 4d8ebc5 commit 6296a1d
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions python/lsst/resources/schemeless.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import logging
import os
import os.path
import stat
import urllib.parse
from pathlib import PurePath

Expand Down Expand Up @@ -85,10 +86,23 @@ def isdir(self) -> bool:
Notes
-----
Always returns the result relative to the current directory unless
it has been pre-declared that this URI refers to a directory.
If the URI is not known to refer to a file or a directory the file
system will be checked. The relative path will be resolved using
the current working directory. If the path can not be found, `False`
will be returned (matching `os.path.isdir` semantics) but the result
will not be stored in ``dirLike`` and will be checked again on request
in case the working directory has been updated.
"""
return self.dirLike or os.path.isdir(self.ospath)
if self.dirLike is None:
try:
status = os.stat(self.ospath)
except FileNotFoundError:
# Do not update dirLike flag.
return False

# Cache state for next time.
self.dirLike = stat.S_ISDIR(status.st_mode)

Check warning on line 104 in python/lsst/resources/schemeless.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/resources/schemeless.py#L104

Added line #L104 was not covered by tests
return self.dirLike

def relative_to(self, other: ResourcePath) -> str | None:
"""Return the relative path from this URI to the other URI.
Expand Down

0 comments on commit 6296a1d

Please sign in to comment.