diff --git a/src/python/jw/pkg/lib/FileContext.py b/src/python/jw/pkg/lib/FileContext.py index 1672f317..e238c7c3 100644 --- a/src/python/jw/pkg/lib/FileContext.py +++ b/src/python/jw/pkg/lib/FileContext.py @@ -276,9 +276,10 @@ class FileContext(abc.ABC): async def file_exists(self, path: str) -> bool: return await self._file_exists(self._chroot(path)) - async def _is_dir(self, path: str) -> bool: + async def _is_dir(self, path: str, follow_symlinks: bool) -> bool: + import stat try: - return S_ISDIR(await self._stat(path).st_mode) + return stat.S_ISDIR((await self._stat(path, follow_symlinks)).mode) except NotImplementedError: log(DEBUG, f'{self.log_name} doesn\'t implement stat(), judging by trailing slash if {path} is a directory') return path[-1] == '/' @@ -290,8 +291,8 @@ class FileContext(abc.ABC): raise return False - async def is_dir(self, path: str) -> bool: - return self._is_dir(self._chroot(path)) + async def is_dir(self, path: str, follow_symlinks=True) -> bool: + return await self._is_dir(self._chroot(path), follow_symlinks=follow_symlinks) @classmethod def create(cls, uri: str, *args, **kwargs) -> Self: diff --git a/src/python/jw/pkg/lib/ec/Local.py b/src/python/jw/pkg/lib/ec/Local.py index f150b2f8..84787b34 100644 --- a/src/python/jw/pkg/lib/ec/Local.py +++ b/src/python/jw/pkg/lib/ec/Local.py @@ -172,5 +172,7 @@ class Local(Base): async def _chmod(self, path: str, mode: int) -> None: os.chmod(path, mode) - async def _is_dir(self, path: str) -> bool: + async def _is_dir(self, path: str, follow_symlinks: bool) -> bool: + if (not follow_symlinks) and os.islink(path): + return False return os.path.isdir(path)