FileContext: Add readdir() and recursive directory copy #131
Loading…
Reference in a new issue
No description provided.
Delete branch "jan/feature/20260929-filecontext-add-readdir-and-recursive-directory-copy"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
FileContext could address single files but neither list a directory nor mirror a tree between contexts; this PR adds the missing pieces:
readdir()enumerates directory entries portably across the context families, andutil.copy()gains a recursive mode that uses it to mirror a directory source below the destination root.lib.FileContext: Add readdir() method
FileContext offers
get(),put(),unlink(),mkdir(), andstat(), 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(), returningIterable[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 raisesNotImplementedErrorby default.Implement
_readdir()in the context families:Local._readdir():os.listdir()ExecContext._readdir(): runsls -1Aand splits the output into one entry per line; inherited bySSHClientand the other command-based contextsCurl._readdir(): raisesOSErrorwitherrno.ENOSYSAdd unit tests covering
Local(listing, hidden entries, missing directory) andCurl(ENOSYS).util.copy(): Add recursive directory copy
copy()copies a single file: it fetches the source root as one content and puts it at the destination, so addressing a directory source fails, and there is no way to mirror a tree between file contexts.Add a recursive mode:
readdir(), destination directories are created level by level, and every leaf is put with the requested owner, group, and modeposix copyexposes the mode as-r/--recursive; the help test reference picks up the new option.