lib.util.copy(): Support FileContext source, file types, and --parents #144
Loading…
Reference in a new issue
No description provided.
Delete branch "jan/feature/20261017-lib-util-copy-support-filecontext-source-file-types-and-parents"
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?
This makes lib.util.copy() more versatile. The PR's net gain is the addition of a parents argument and a FileContext source type to copy()'s signature, and support for faithfully copying file types under the hood.
On the way there,
FileContextgainsis_gettable()and thechrootread-only property, so callers can tell which nodesget()reaches and how a context's addresses compose.copy()builds on that: the recursive walk drops the chain-creating__mkdir_p()for a plain per-nodemkdir(), the source's file types are threaded through to the landing, aFileContext— notably a chrooted one — is accepted as a tree source, and compound nodes are copied whole instead of descended into. The parents flag lands a single source at its source path, ascp --parentsdoes, and the copy CLI command exposes it as--parents.lib.FileContext.is_gettable: Add property
Analogous to the
is_dir()method, add anis_gettable()method: The last commit introducesFT_COMPOUND, a file type which is a hybrid between directory and regular file.is_dir()succeeds on it, sois_gettable()symmetrically provides a test find out ifget()also works on a file.lib.FileContext.chroot: Add property
Give
FileContexta read-only property to accessself.__chroot, so a caller holding a context can predict whether the addresses it passes in are relative to the URI path or absolute.lib.util.copy(): Remove __mkdir_p()
Refactor
copy(), making the recursive logic more coherent: Every node the walk creates sits below a node that already exists, so a plain per-nodemkdir()suffices and the chain- creating__mkdir_p()is dropped: the landing root's parent must exist now, as incp -r.lib.util.copy(): Copy file types
The file type framework gives
mkdir()andput()an ftype argument, butcopy()calls them untyped, so the source's node types are discarded at the landing: a destination that applies its own node types receives only the defaults.This commit threads the source's types through.
lib.util.copy(): Accept a FileContext as source
Using a
FileContext, notably with its chroot flag set, is useful as a tree source incopy(), so allow it.lib.util.copy(): Add parents flag parameter
copy()lands a source below the destination root, taking at most the source's basename, so there is no way to land it at its source path, as cp--parentsdoes.Add a parents flag that requests just that.
lib.util.copy(): Terminate the walk at compound nodes
The walk needlessly descends into every directory node: A compound node is gettable as a whole, so copy it over and don't recurse deeper.
cmds.posix.CmdCopy: Add --parents
copy()can now land a single object at its source path, but the copy CLI command exposes no way to ask for it.Add a
--parentsflag forwarded tocopy()'s parents argument.