lib.util.copy(): Support FileContext source, file types, and --parents #144

Merged
Jan Lindemann merged 8 commits from jan/feature/20261017-lib-util-copy-support-filecontext-source-file-types-and-parents into master 2026-10-17 11:57:05 +02:00 AGit
Owner

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, FileContext gains is_gettable() and the chroot read-only property, so callers can tell which nodes get() 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-node mkdir(), the source's file types are threaded through to the landing, a FileContext — 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, as cp --parents does, and the copy CLI command exposes it as --parents.

lib.FileContext.is_gettable: Add property

Analogous to the is_dir() method, add an is_gettable() method: The last commit introduces FT_COMPOUND, a file type which is a hybrid between directory and regular file. is_dir() succeeds on it, so is_gettable() symmetrically provides a test find out if get() also works on a file.

lib.FileContext.chroot: Add property

Give FileContext a read-only property to access self.__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-node mkdir() suffices and the chain- creating __mkdir_p() is dropped: the landing root's parent must exist now, as in cp -r.

lib.util.copy(): Copy file types

The file type framework gives mkdir() and put() an ftype argument, but copy() 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 in copy(), 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 --parents does.

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 --parents flag forwarded to copy()'s parents argument.

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, `FileContext` gains `is_gettable()` and the `chroot` read-only property, so callers can tell which nodes `get()` 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-node `mkdir()`, the source's file types are threaded through to the landing, a `FileContext` — 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, as `cp --parents` does, and the copy CLI command exposes it as `--parents`. #### lib.FileContext.is_gettable: Add property Analogous to the `is_dir()` method, add an `is_gettable()` method: The last commit introduces `FT_COMPOUND`, a file type which is a hybrid between directory and regular file. `is_dir()` succeeds on it, so `is_gettable()` symmetrically provides a test find out if `get()` also works on a file. #### lib.FileContext.chroot: Add property Give `FileContext` a read-only property to access `self.__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-node `mkdir()` suffices and the chain- creating `__mkdir_p()` is dropped: the landing root's parent must exist now, as in `cp -r`. #### lib.util.copy(): Copy file types The file type framework gives `mkdir()` and `put()` an ftype argument, but `copy()` 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 in `copy()`, 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 `--parents` does. 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 `--parents` flag forwarded to `copy()`'s parents argument.
Analogous to the is_dir() method, add an is_gettable() method: The last
commit introduces FT_COMPOUND, a file type which is a hybrid between
directory and regular file. is_dir() succeeds on it, so is_gettable()
symmetrically provides a test find out if get() also works on a file.

Signed-off-by: Jan Lindemann <jan@janware.com>
Give FileContext a read-only property to access self.__chroot, so a caller
holding a context can predict whether the addresses it passes in are
relative to the URI path or absolute.

Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.0.1
Refactor copy(), making the recursive logic more coherent: Every node the
walk creates sits below a node that already exists, so a plain per-node
mkdir() suffices and the chain- creating __mkdir_p() is dropped: the
landing root's parent must exist now, as in cp -r.

Signed-off-by: Jan Lindemann <jan@janware.com>
The file type framework gives mkdir() and put() an ftype argument, but
copy() 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.

Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.1.0
Using a FileContext, notably with its chroot flag set, is useful as a
tree source in copy(), so allow it.

Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.1.0
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
--parents does.

Add a parents flag that requests just that.

Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.1.0
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.

Signed-off-by: Jan Lindemann <jan@janware.com>
cmds.posix.CmdCopy: Add --parents
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 4m54s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 5m0s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 4m50s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 4m42s
CI / Packaging test (push) Successful in 0s
e5656d7d18
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 --parents flag forwarded to copy()'s parents argument.

Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.1.0
Jan Lindemann scheduled this pull request to auto merge when all checks succeed 2026-10-17 11:47:08 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
janware/jw-pkg!144
No description provided.