lib.FileContext.is_dir(): Add follow_symlinks
Make FileContext.is_dir() usable: - Add follow_symlinks parameter meant to do the obvious - Fix missing await
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
b5762116a1
commit
6cfb86d2a7
2 changed files with 8 additions and 5 deletions
|
|
@ -276,9 +276,10 @@ class FileContext(abc.ABC):
|
||||||
async def file_exists(self, path: str) -> bool:
|
async def file_exists(self, path: str) -> bool:
|
||||||
return await self._file_exists(self._chroot(path))
|
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:
|
try:
|
||||||
return S_ISDIR(await self._stat(path).st_mode)
|
return stat.S_ISDIR((await self._stat(path, follow_symlinks)).mode)
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
log(DEBUG, f'{self.log_name} doesn\'t implement stat(), judging by trailing slash if {path} is a directory')
|
log(DEBUG, f'{self.log_name} doesn\'t implement stat(), judging by trailing slash if {path} is a directory')
|
||||||
return path[-1] == '/'
|
return path[-1] == '/'
|
||||||
|
|
@ -290,8 +291,8 @@ class FileContext(abc.ABC):
|
||||||
raise
|
raise
|
||||||
return False
|
return False
|
||||||
|
|
||||||
async def is_dir(self, path: str) -> bool:
|
async def is_dir(self, path: str, follow_symlinks=True) -> bool:
|
||||||
return self._is_dir(self._chroot(path))
|
return await self._is_dir(self._chroot(path), follow_symlinks=follow_symlinks)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, uri: str, *args, **kwargs) -> Self:
|
def create(cls, uri: str, *args, **kwargs) -> Self:
|
||||||
|
|
|
||||||
|
|
@ -172,5 +172,7 @@ class Local(Base):
|
||||||
async def _chmod(self, path: str, mode: int) -> None:
|
async def _chmod(self, path: str, mode: int) -> None:
|
||||||
os.chmod(path, mode)
|
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)
|
return os.path.isdir(path)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue