The first Ctrl-C cancels the running task while the SSH connection is still
open, but _run_ssh() has no cleanup: the connection is abandoned and the
remote process is never signalled. A long-running command such as zypper
dup therefore keeps running after the client dies, taking its children with
it and leaving the system in a half-baked state, e.g. a mid-air package
transaction.
Catch the cancellation inside the run, forward SIGINT to the remote
process, and wait for it to exit, draining the captured output, before
propagating the cancellation.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.2
Signed-off-by: Jan Lindemann <jan@janware.com>
Do the filtering outside of KvFile, in a standard way.
KvFile currently instantiates its backend distro with a self-instantiated
backend filter, and doesn't propagate the filter passed to its ctor up to
its base class. This arrangement makes it hard to ensure the class behaves
in a standardish way. Allowing the base class filter to do its work, and
not pass any filter to the backend context, is the more straightforward
architecture, this is what this commit does.
The base class still has some freedom to create a filter. Override the base
class's _create_path_filter() to make sure that filter is a PkgSecrets /
pkg-secrets: filter, anything else is not thought through at this point.
Signed-off-by: Jan Lindemann <jan@janware.com>
The on-host store scopes its address space to the config paths backed by
installed packages, but the scope lives inside KvFile: it derives the set
from the distro itself and consults it in the individual operations. A
context that carries a filter must behave as the filter mandates, so the
wanted set belongs in a filter of its own.
Add the pkg-secrets path filter, a Pkg whose space is the config paths
of the matching packages' template files - the path with the .jw-tmpl
suffix stripped - plus the directories leading to them. A compound or
blob address maps to its config path, a key address to the config path
of the compound it lives under; any other address is judged on its own.
The spec form follows pkg: a bare spec matches every installed package,
and pkg-secrets:url=~REGEX narrows the backing set to packages whose url
matches. Pkg parses its criterion through an overridable _parse_spec(), and
its _match_pkg() matches every package on a None criterion, so both filters
share the parsing and matching code.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.2
Signed-off-by: Jan Lindemann <jan@janware.com>
Rename lib.ec.secret_store.layout.content_name() to target_name() and
KvFile's config_path to target_path(). "Target" is a better name to settle
on instead of "config" or "content". It's used in other contexts, too,
referring to secret compilation output.
Signed-off-by: Jan Lindemann <jan@janware.com>
Distro.paths() now allows to spare a detour in Pkg._access() - we can
directly get to the list of paths instead of via Distro.select() ->
pkg_paths().
Signed-off-by: Jan Lindemann <jan@janware.com>
After the introduction of path-based filters, accompany the existing
pkg_paths() method by a more fine-grained paths() method, taking a
PathFilter instead of a PackageFilter. It additionally takes a "pkg_names"
argument, which is then dispatched to the filter if it's a package filter.
The API isn't glorious, but works for now and is easily changeable in the
future: **kwargs comes to mind, or a PackageFilter which brings its own
package names.
Signed-off-by: Jan Lindemann <jan@janware.com>
PathFilter.create() currently instantiates individual filters in a match -
case over the filter URI's protocol. The plan is to instantiate filters
without match / case based on a protocol naming scheme only, so we better
introduce one at this point. Adopt jw-python's kebab_to_pascal() and
pascal_to_kebab() functions as a foundation for a future naming convention.
Signed-off-by: Jan Lindemann <jan@janware.com>
"files" is a term that can be used for many aspects of a file, its path,
its content, a handle, so better use "pkg_paths" instead of "pkg_files" for
Distro's method to inform about which files a package holds. That also
aligns better with the recent move from PackageFilter toward PathFilter.
Signed-off-by: Jan Lindemann <jan@janware.com>
ExecApp's --target parameter and the ec.Local.__init__()'s uri argument carry
"local" as their default value which was meant as a keyword but doesn't pass
as an URI. Fix that.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
Signed-off-by: Jan Lindemann <jan@janware.com>
apt 3.x distinguishes versions with the same version number by their
control metadata, so a .deb installed with dpkg -i that differs from the
repository's same-version package is regarded as a separate version, and
apt-get install of the package name "upgrades" it to the repository
version, replacing the installed package. If the installed package was
built from the source code repo's master, this is effectively a downgrade
and can break a CI run in currently unintended ways.
This commit detects same-version packages in apt-get's install todo list by
running apt-get -s install (simulate installation), parsing the output, and
removing those packages from the command line of the subsequent, real
install command.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
Signed-off-by: Jan Lindemann <jan@janware.com>
The exec context's default filter selects paths, not just packages, so the
pkg spelling of the option and environment variable that set it no longer
fit. Rename both and some variables accordingly:
- ExecApp: --pkg-filter becomes --path-filter, and the fallback environment
variable JW_DEFAULT_PKG_FILTER becomes JW_DEFAULT_PATH_FILTER
- Distro: the default_pkg_filter constructor argument and property become
default_path_filter, matching FileContext, ExecContext, and CopyContext;
App and KvFile pass the renamed argument
- Adapt the help test's expected output and the unit tests
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
Drop the re-read of JW_DEFAULT_PKG_FILTER, and derive the filter from the
ctor and URI like all other FileContext instances would. Use that to filter
the backend for the packages provinding secrets.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
PackageFilterString and Pkg are duplicates. The PackageFilter and
FileContextFilter base classes live in lib/PackageFilter.py, imported by
Pkg, Distro, and the tests.
Move the two base classes into lib/pf/Pkg.py (where Pkg already lives),
drop PackageFilterString, delete lib/PackageFilter.py, and repoint Distro
and the tests to the new location. Move the test suite with the module to
test/.../pf/Pkg/.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
This commit moves package-based filtering from the package level to the
path level, using the new path filter framework. Derive PackageFilter from
a new FileContextFilter base, which binds a PathFilter to the FileContext
it guards, and implements _access().
The filter's space is the file list of the packages it selects, taken from
the backing distro's pkg_files(). An address is allowed only if it names
one of those files.
The backing distro is taken from the file context, if the context carries
one, and is otherwise autodetected from the host the context executes on,
so the filter also works on a bare exec context. A context that is not an
exec context and carries no distro rejects path queries with an error.
The filter string now follows the loader syntax, pkg:url=~ regex, and
a bare url=~regex like the old url=~jw.dev form is rejected; update
JW_DEFAULT_PKG_FILTER values accordingly.
PackageFilter's match() is renamed match_pkg(), to make clear that it
matches packages, and Distro._select() calls the new name.
ExecApp.path_filter builds the filter through PathFilter.create() and
binds it to the exec context. CmdSelect passes its argument to the new
constructor, CmdCopy hands the app's filter to the copy, and the App distro
picks it up as the default package filter.
Extend the unit test to cover the space membership and the distro lookup.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
Allow to attach a default path filter to a FileContext, given in the
constructor as default_path_filter, or in the URI query as "path-filter".
Passing False as default_path_filter will make the FileContext ignore any
path-filter in the query.
The filter is created lazily on first use through PathFilter.create(), so a
string spec is loaded from the lib.pf module like any other filter.
Every path based action evaluates the filter before it is carried out.
An IGNORE verdict is logged and the action is skipped: reads and stats
raise FileNotFoundError, writes, unlinks, erases, renames, and mkdirs are
no-ops, and readdir() drops the filtered entries. An ABORT verdict raises
PermissionError.
Every path-driven method also takes a flag parameter, "filtered",
defaulting to True, so a caller that must work regardless of the context's
filter can opt out of the check.
Add a unit test that exercises the verdicts, the filtered bypass, and the
distribution probe on a Local context.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
Add the abstract PathFilter class, designed to be attached to a FileContext
in later commits. This is the first commit of a series that generalizes the
JW_DEFAULT_PKG_FILTER / --pkg-filter framework into loadable path filters
that can be attached to any FileContext.
A filter answers an access check, _access(), with a bool. run() turns the
answer into a verdict: ALLOW when the check passes, otherwise ABORT or
IGNORE according to the filter's deny action, LOG or ABORT. The verdict is
handled by the filter's handle, a pair of per-verdict gates: with the ABORT
gate set, an ABORT verdict raises PermissionError; with the LOG gate set,
an IGNORE verdict is logged and returned. A verdict whose gate is not set
passes through unhandled.
Also add the lib.pf module that hosts the concrete filters. A filter spec
of the form foo:something is loaded by PathFilter.create() as the Foo class
from the jw.pkg.lib.pf.Foo module. A spec without the name prefix, or a
name that no module provides, is rejected with an error that names the
expected class and module.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
copy() handed a non-recursive copy of a directory to the single-object
get() path. For a plain context the backend then fails with a transport
error, and for a kvfile store the store root is a branch, not an entry,
so the get() fails with a FileNotFoundError naming a transformed address:
copying "kvfile:///etc" reported "FileNotFoundError: etc".
Require recursive for a directory source that is not fetchable as a whole,
as cp requires -r for directories: copy() now raises with a message naming
the source and the recursive option, instead of falling through to get().
Add a unit test that covers a directory source for a plain context and a
kvfile store.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
SERVICE_SECRET[n] keys of an entry are used as rotation metadata by
downstream software, and their values don't need to be kept secret: they
name the macro and the account that owns it. Encrypting them buys nothing,
and it forces every annotation tool to decrypt and re-encrypt the whole
entry for a one-line read or edit.
Run sops encrypt with --unencrypted-regex SERVICE_SECRET, so the annotation
keys stay plain text in the repository file and the store stays greppable
without the age key, and with --mac-only-encrypted, so the MAC covers the
encrypted values only and the annotation lines can be edited as plain text
without invalidating the file.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
A directory node of the store, the root included, stats as a directory, but
a get on it falls through to the key lookup below its parent and fails with
a FileNotFoundError naming a path the caller never asked for: get() on the
root fails with an empty name, get() on a branch with its parent's compound
path.
Raise IsADirectoryError from _get() when the path is a directory on the
host, after the compound and the blob lookups, so get() and stat() agree: a
directory stats as FT_DIR and refuses a get.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
Signed-off-by: Jan Lindemann <jan@janware.com>
KvFile.__init__() accepts a host FileContext plus an optional Distro, and
the two may live on different hosts. In effect, files are read from one
host based on another host's package set, which may have its use cases but
is generally undesirable. The context parameter also breaks the uniformity
of the store constructors: Sops, TarGpg, and Vault are constructed from a
URI alone, and FileContext.create() needs a special case that builds the
kvfile store's inner context before handing it to the constructor.
This commit has KvFile constructed from a URI alone like the other stores.
The URI's authority names the host, no authority means "local", and the
constructor builds the inner context through FileContext.create() with
chroot off, forwarding the store's constructor parameters to it. The inner
context is always an exec context, which the distro derivation needs: it is
lazy, Distro.instantiate() runs on the first file listing, with the
JW_DEFAULT_PKG_FILTER environment variable as the default package filter,
as before.
Adapt all call sites:
- FileContext.create(): the kvfile case returns KvFile(uri) directly.
- FilesContext: the distro parameter goes; the store URI is derived from
the exec context's scheme, authority, and path, so a local context with a
hostname in its URI stays local.
- DistroContext.install(): the kvfile source wrap goes; the compounds read
directly through the source context with parse_kv().
- The store tests monkey-patch Distro.instantiate() for the stores that
list something
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
Signed-off-by: Jan Lindemann <jan@janware.com>
Uri exposes the query as a raw string only, so a consumer that wants the
query's key/value pairs has to parse the string itself with urllib.parse.
Add a cached property query_dict that returns None when the Uri has no
query and a dictionary of the query's key/value pairs when it does.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
Signed-off-by: Jan Lindemann <jan@janware.com>
lib.Uri doesn't support query strings, and this commit adds support: Expose
the query as a property, keep it through the path replacement methods, and
show it in the full forms.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.4.0
The install methods of Distro inconsistently resolve dependencies or don't
depending on the descendant's implementation. Pin that more unambigously by
adding a new parameter install_deps, defaulting to True, to the following
methods of lib.Distro:
_install_local_files()
_install_urls()
_install_urls_and_names()
install()
The implementations in lib.distros.* make use of the new
lib.pm.*.install_packages() method introduced by the previous commit.
Add a unit test directory per Distro descendant.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.4.0
Signed-off-by: Jan Lindemann <jan@janware.com>
Currently, jw-pkg install is sometimes left to the high-level package
manager, which is allowed to install dependencies along, and that's
sometimes unwanted, but there's no backend in the low-level package manager
module lib.pm to allow specifying that. This commit adds it:
lib.pm.*.install_packages().
The functions install a list of local package files using the low-level
package managers rpm / dpkg, bypassing the high-level package managers yum
/ apt / zypper.
pm.rpm runs rpm -U and pm.dpkg runs dpkg -i. Every file is classified
against the installed state of its package, queried by name: a file
for a package that is not installed is installed fresh, a file with
another version installed is upgraded, and a file whose version is already
installed is reinstalled when force is set and skipped otherwise. On rpm,
plain -U refuses a package that is already installed, and --reinstall
aborts the transaction when a file of the incoming package differs from
the installed one, so the upgrades run before the reinstalls and the
same-version files need force.
With only_update, a file for a package that is not installed raises before
anything is installed.
The dpkg route is gated on an apt simulation, because dpkg -i leaves a
half-configured package when a dependency is missing: the simulation runs
first and the install is refused when it would install or remove anything
but the given files' own packages.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.4.0
Signed-off-by: Jan Lindemann <jan@janware.com>
Add a version field to the Package class and make query_packages() fill it.
It's very much distribution and package dependent what shape that version
has, so from Package's perspective, it's just a str-typed member.
Further improvements and fixes:
- Make query_packages() accept throw, defaulting to the previous behaviour,
so a caller that wants to be prepared for a missing package / an empty
result can pass throw = False.
- Make dpkg's _run() and run_dpkg_query() forward ec and the remaining
keyword arguments on the sudo path, which dropped them before.
Add unit tests for the file type tree and its StatResult predicates.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.4.0
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit adds the Vault store and the vault:// dispatch in FileContext.
A Vault KV v2 server maps nicely into jw-pkg's secret handling abstraction
as just another secret store backend. Environment variables identify the
storage details, analogous to the way it's handled in the SOPS backend.
- JW_SECRETS_VAULT_ADDR names the server, a unix socket address or an http
URL; the standard VAULT_ADDR is never read; JW_SECRETS_VAULT_MOUNT the
mount path, default secret; the token is the standard VAULT_TOKEN
- The transport is one curl per API call, through the Local context: a
unix:// server is reached through its socket, an http:// server through
its port
- A node's type is derived at stat time: an entry, a blob, a key below an
entry, a branch if the path has children, otherwise a miss
- A blob's content is base64 under a single key of its KV secret, the
marker being a path component, so a KV secret that is not a blob is
always an entry
The test drives a dev server fixture from the workspace: stat/readdir/get
on the fixture, the default fallback, the storage marker, and the copy
forms - single key, whole entry, recursive entry, deploy to the on-host
layout, and a host subtree.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.2.0
This commit adds a new class inheriting from secret_store.Base: Sops. The
currently available classes allow to store secrets offline in a
GPG-encrypted tarball, but those are not versioned. This commit allows to
use a SOPS / AGE-encrypted Git repository as storage backend instead.
The additions in detail:
- Sops: the store implementation; the repository location comes from
JW_SECRETS_SOPS_REPO, get() on an entry returns the decrypted serialized
content, and a typed put (FT_SECRET) re-encrypts the entry wholesale
- The age key comes from JW_SECRETS_SOPS_KEY_PATH only: the house variable
is the sole input to the store, and SOPS_AGE_KEY_FILE is set on the sops
subprocess per invocation, never read from the process environment;
SopsKeyError is raised when the variable is not set
- FileContext.create(): the sops:// scheme
- The store's unit tests, covering the node types, the deploy and fetch
round trip, the whole-entry get and put, the key resolution, and the
default fallback
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.1.0
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 TarGpg store is read-only: put() and unlink() raise, so the store can
be copied from, but not into, and a copy that lands entries and blobs below
a host prefix has no tarball target.
This matches the way jw-pkg secrets has worked for a long time. Since
Stores are now FileContext-backed, a write path can be cleanly implemented,
and that's what this commit does.
A put rebuilds the tarball: the existing members minus the removed, plus
the written one; the result is signed with the recipient from
JW_SECRETS_TARGPG_RECIPIENT and written back to the tarball location, which
must be a local path. A missing tarball is an empty store, so a put creates
it.
The put dispatch follows the other stores: a typed entry put replaces the
entry with the given serialized content, a key put merges into its entry,
creating it if it does not exist yet, and an untyped put below an entry
lands a key there, otherwise a blob. unlink() removes the node's member.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.1.0
"jw-pkg secrets install" copies secret material from a GPG-encrypted tar
archive to dotenv .jw-secret files on a target host. This commit refactors
the underlying code and adds hooks for the inverse copy direction, and for
more secret sources and targets.
The peers between which secrets are copied are represented by the new
abstract secret_store.Base class, and the existing tar blob and host
storages, inheriting from that class, are TarGpg and KvFile. Moreover,
secret_store.Base is inheriting from FileContext, so all of jw-pkg's
file-like operations are available as hooks.
Secrets inside instances of two file contexts are addressable as
(targpg|kvfile)://target.host.com/path/to/file.conf.jw-secret. The on-host
KvFile will look either locally or via SSH for that file, and TarGpg will
look inside a tar archive specified in the JW_SECRETS_TARGPG_TAR
environment variable.
Uris with these schemas can be passed to FileContext.create(), which will
return a chrooted file context of the correct type.
KvFile.stat("/path/to/file.conf.jw-secret").ftype is FT_SECRET which
inherits from FT_COMPOUND - which means that readdir() works on such
animals. Not entirely sure if that's a good idea, but it feels pretty
generic. Let's see where that takes us.
DistroContext.install() after this refactor reads its source through the
store interface and writes the landing through the KvFile store.
Both secret stores are exercised through the existing unit test of jw-pkg
secrets install, and unit tests for both stores are also added by this
commit.
Signed-off-by: Jan Lindemann <jan@janware.com>
Add a write-through read cache in front of a file context.
stat() and get() results are cached: stat per (path, follow_symlinks), get
per (path, wd, throw). Successful stats and FileNotFoundErrors are cached;
other errors are re-probed, so a transient transport failure does not
poison the cache. Writes pass through to the wrapped context and drop the
cache entries of the affected paths. The existence and directory checks are
rerouted through the cached stat, so they pay the cache instead of the
wrapped context's own fast path.
warm() fills the stat cache of a set of paths, as file_exists() would stat
them, without following symlinks. If the wrapped context is an exec
context, one host command stats all of the paths; otherwise, one stat per
path runs.
The GNU stat format of ExecContext is lifted to the module constant
STAT_GNU_FORMAT, and the field parser is exported as parse_stat_fields(),
so warm() fills entries that are indistinguishable from a real stat().
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.1.0
Signed-off-by: Jan Lindemann <jan@janware.com>
Add a file context that sits in front of another one and delegates every
primitive call to it.
The wrapper adopts the identity of the wrapped context: uri, root, chroot
flag, and the chroot path composition are the wrapped context's, so a path
composed by the wrapper composes identically in the wrapped context. Every
primitive is forwarded to the wrapped context's primitives, which receive
the already-composed path; open() and close() are forwarded to the wrapped
context's public methods, so the open count is kept in one place.
The point is to give derived contexts a stable base: a caching context, or
any other filter, overrides the primitives it cares about and inherits the
rest, instead of re-deriving the chroot bookkeeping of every method.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.1.0
Signed-off-by: Jan Lindemann <jan@janware.com>
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
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
Add the "packages verify" command: it runs Distro.verify() with the app's
package filter and prints one line per flagged file.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.2.0
jw-base verify pipes the output of rpm -qV for all janware packages
into a grep for md5 mismatches and missing files. The same capability,
distribution-independent, belongs in the Distro abstraction so that tools
like jw-nettools can check the integrity of the packages they install on a
fleet of hosts.
- Add Distro.verify(), which verifies the given package names, or all
packages selected by the package filter when none are given, and returns
the flagged files
- Add Distro._verify() as the distribution hook
- Add FlaggedFile, the record for a flagged file: package, file, and the
package manager's verify status line - not distribution independent as of
today, but it's a start
- pm/rpm.py: parse_verify_output() parses the output of `rpm -qV` and
reports md5 mismatches and missing files, the latter reported with the
literal word "missing" in the flag field; size, mode, mtime, user, and
group mismatches are noise on dev machines and are ignored.
verify_packages() runs `rpm -qV` per package and collects the findings
- pm/dpkg.py: parse_verify_output() parses the output of `dpkg -V` and
reports md5sum (P) mismatches and missing files (M); verify_packages()
runs `dpkg -V` per package
- The SUSE, Red Hat, and Debian Distro classes implement _verify() with the
respective pm helpers; the Arch Distro raises NotImplementedError, like
its other package manager hooks
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.2.0
Distro.pkg_files() takes a package name and returns a list of files in that
package. This commit generalizes that - pass None to it and get the list of
all packaged files in the system, and pass a list of strings to retrieve
all files belonging to the named packages.
The same arguments are propagated to _pkg_files(), which in turn propagates
them to list_files().
This allows faster generation of file lists than before. Having to retrieve
a list of matching packages and query each package for its contained files
can be collapsed into one or two backend calls.
Signed-off-by: Jan Lindemann <jan@janware.com>
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:
- a directory source is mirrored below the destination root, into it if the
root is an existing directory, as it if it does not exist yet
- entries are enumerated with readdir(), destination directories are
created level by level, and every leaf is put with the requested owner,
group, and mode
- a file source is unaffected, and the destination parent must exist, as
before
posix copy exposes the mode as -r/--recursive; the help test reference
picks up the new option.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.87.1
Signed-off-by: Jan Lindemann <jan@janware.com>
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>
Use Version.next() in __version_boundaries, which steps the last existing
part, so '= 1.0' spans '>= 1.0, < 1.1'.
Tests written by AI.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1
Signed-off-by: Jan Lindemann <jan@janware.com>
Range expansion needs a bound that steps the last existing part of a
version, add that.
next() increments the last part, whatever it is: next of '1' is '2', of
'1.0' is '1.1', of '1.2.3' is '1.2.4', of '1.2.3-45' is '1.2.3-46'.
Tests written by AI.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1
A multi-boundary constraint is rendered as 'foo >= 1.2.3-45 foo < 1.2.4',
which is invalid: the RPM spec template writes the Requires: line from it
verbatim, and RPM entries are comma-separated, so the second clause is
swallowed into one bad entry. Debian's format_depends() normalizes runs of
whitespace to commas, so it tolerates the space join, but the comma is the
only delimiter that is correct for both.
Join the boundary clauses with ', ' instead of a space.
Also:
- Drop the stray trailing comma in the version_boundaries() call.
- Fix the untemplated docstring, which describes the opposite of the code:
untemplated = True (the default) resolves the macros, untemplated = False
keeps them as written.
Tests written by AI.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1
Full version dependency specs ("= 1.2.3-4" or "= VERSION-REVISION") don't
need expansion, they pin the wanted version with an = fine exactly.
__version_boundary has that the wrong way around, fix that.
Also fix the is_full and version_boundaries() docstrings, which still
describe the old behavior.
Tests written by AI.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1
Signed-off-by: Jan Lindemann <jan@janware.com>
__resolved_id() returns the full version if only VERSION was specified, fix
that.
Also: raise Version.Error instead of a bare Exception.
Tests written by AI.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1
Signed-off-by: Jan Lindemann <jan@janware.com>
TarIo._match() and _filter_tar_file() are pure logic without test coverage.
Add unit tests for the exact path matching, the unfiltered round trip,
filtered extraction with a matched list, and a filter without hits.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1
PackageFilterString is pure regex logic without test coverage.
Add unit tests for the url=~ filter, packages without a url, whitespace
around the operator, and the rejection of unsupported filter definitions.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1
ProcPipeline and the run() helper are pure logic without test coverage.
Add unit tests for the identity filter, chained filter execution order, the
append() layouts, and the chain handling of run().
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1
parse_spec_str(), parse_specs_str(), order_tags(), and __repr__ are pure
text processing without test coverage, shared by the dpkg and rpm package
manager backends.
Add unit tests for valid and invalid spec strings, multi-line input with
and without a trailing newline, tag ordering with default values, and the
repr layout.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1
__init_askpass() embeds the password verbatim in a generated bash script,
with a newline included inside the double quotes of the echo -n. The
askpass program therefore always appends a newline to the password, and
any password containing quotes or shell metacharacters either breaks the
script or injects commands into it.
Embed the password as base64 and decode it with printf piped into base64
-d, so the script is safe for any password and prints the password exactly,
byte for byte.
Make __del__() idempotent: it deletes the environment variables and the
script file, so a second call, e.g. an explicit one followed by garbage
collection, raises KeyError and FileNotFoundError.
Add a unit test that executes the generated script and compares its output
with the password byte for byte.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1
expand_macros() looks up each %{name} via getattr with '-' turned into '_',
but macro_names advertises two names that don't resolve: 'os-release' has
no corresponding attribute, and 'os-cascade' resolves to the list property
os_cascade, which str.replace() rejects. Both macros are listed in the
platform info help output, yet always fail when used in a format string.
The space-joined cascade string is the cascade property, and 'cascade' is
the macro name the make recipes and scripts already use, together with the
--format default in cmds/platform/CmdInfo.py.
Before the App.distro_* properties moved to Distro, the advertised macro
names were derived from the distro_* attribute names, so the advertised
macro was %{cascade}; the hand-written macro_names replaced it with the
list attribute's name.
- Add the missing os_release attribute as an alias of os_release_str
- Advertise the 'cascade' macro in macro_names instead of 'os-cascade',
leaving os_cascade as the purely programmatic list
- Update the platform info help expected output accordingly
- Add unit tests for the os-release field parsers, the derived properties,
and the expansion of every advertised macro
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1