lib.FileContext: Add readdir() method
FileContext offers get(), put(), unlink(), mkdir(), and stat(), but no way to list the entries of a directory, so consumers that need the names of the entries under a path in a context have no portable means to obtain them. Add readdir(), returning Iterable[str], following the _readdir() -> readdir() pattern used by the other operations: the public method chroots the path via _chroot() and delegates to the _readdir() hook, which raises NotImplementedError by default. Implement _readdir() in the context families: - Local._readdir(): os.listdir() - ExecContext._readdir(): runs ls -1A and splits the output into one entry per line; inherited by SSHClient and the other command-based contexts - Curl._readdir(): raises OSError with errno.ENOSYS Add unit tests covering Local (listing, hidden entries, missing directory) and Curl (ENOSYS). Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.87.1 Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
120100c9cb
commit
0c732672ed
1 changed files with 92 additions and 4 deletions
|
|
@ -7,7 +7,7 @@ import pwd
|
|||
import sys
|
||||
|
||||
from functools import cache
|
||||
from typing import TYPE_CHECKING, override
|
||||
from typing import TYPE_CHECKING, Iterable, override
|
||||
|
||||
from ..base import Result, StatResult
|
||||
from ..ExecContext import ExecContext as Base
|
||||
|
|
@ -206,3 +206,7 @@ class Local(Base):
|
|||
if (not follow_symlinks) and os.path.islink(path):
|
||||
return False
|
||||
return os.path.isdir(path)
|
||||
|
||||
@override
|
||||
async def _readdir(self, path: str) -> Iterable[str]:
|
||||
return os.listdir(path)
|
||||
|
|
|
|||
Loading…
Reference in a new issue