sow prune
sow prune keeps the newest RPM for each package name and architecture in a
simple repository, rebuilds the index, and then deletes
the older files. Use it on a directory that collects every release over time, such as a mirror or
a Pigsty offline repository, when only the latest versions should ship. “Newest” follows RPM’s
Epoch/Version/Release rules, including caret snapshot versions such as 2.0^20250611 < 2.0.1. In
a standard repository, set a Dist’s limit instead; prune refuses to
run inside a workspace.
Synopsis
DIR is required. prune reads only the top-level binary RPM files in it (RPM v4 and v6); it does
not scan subdirectories, look for a workspace, or read sow.yml.
Options
| Option | Behavior |
|---|---|
--dry-run |
Preview validated removal candidates without writes |
--strict |
Fail non-zero on corrupt packages, unmatched --protect names, or equal-version conflicts |
--protect NAME |
Keep all versions of an exact package name; repeatable |
-j, --jobs N |
Package inspection workers; defaults to CPU count |
--metadata-timestamp SECONDS |
Index publication time in Unix seconds; defaults to 0, as for create |
-T, --timeout DUR |
Limit the wait for the directory lock |
-N, --no-wait |
Fail immediately if the directory lock is busy |
--json |
Return the standard JSON envelope |
-h, --help |
Show help |
--timeout and --no-wait are mutually exclusive. prune signs neither packages nor metadata
and rejects --pigsty and --passfile.
Preview and prune
Preview first, then run the same command without --dry-run:
A second run on this example reports noop=true. --dry-run validates the packages, lists removal candidates, and warns about conditions such as a signed repomd.xml or unsupported metadata. The preview skips index rendering, so a live run can refresh a stale index even when the preview reports noop=true.
To keep several versions of some packages, protect them by exact name. Pass the same --protect
options to the preview and the real run:
--protect NAME keeps every version of that name on every architecture. It is repeatable and does
not accept patterns.
Run prune on the local publication source, not on the copy clients read. A client that cached
the previous index may still request an RPM that prune just deleted, so let your publication
step keep old files until those caches expire.
Skipped packages and –strict
By default a problem with one package does not stop the run. Corrupt packages, --protect names
that match nothing, and equal-version conflicts (the same EVR with different content) are reported
as warnings and skipped safely; a conflict keeps the whole name/architecture group. If every RPM is
skipped, the previous repodata/ and completion marker stay as they were.
Pass --strict to fail before anything is published instead. The exit code then tells you which
problem it was: 1 for a corrupt or unreadable package, 2 for an unmatched --protect name,
and 6 for a source RPM, an equal-version conflict in an unprotected group, or a directory with no top-level RPMs (including a DEB-only directory). An explicitly protected group keeps all versions and skips the equal-version conflict check.
Text output prints warnings to stderr. A successful --json run puts them in the stdout envelope
and leaves stderr empty. The JSON result has dir, dry_run, kept, candidates (each old
path with its latest replacement), removed, optional skipped and warnings,
index_updated, marker, and noop.
Mixed directories and repo_complete
In a directory that holds DEBs as well, prune updates only the RPM index, leaves the DEB index as
it is, and warns that it operates on RPMs only.
If repo_complete exists, prune withdraws it while it works, recording that state in
.sow-prune-repo-complete so it survives an interruption, and writes a fresh marker only after
completion. DEB entries in the new marker reuse the existing digests for DEBs still present; newly
arrived DEBs that are not indexed yet are not hashed. prune never creates a marker that did not
exist and never applies the create --pigsty cleanup rules.
Supported repositories
prune refuses directories inside a workspace. On a live run it also refuses a directory with
repodata/repomd.xml.asc, an existing repomd.xml that registers metadata SOW does not generate
(groups, updateinfo, modules, or an unknown type), and a previous repomd.xml larger than 16 MiB.
The error names the file to remove, repodata/repomd.xml.asc or repodata/repomd.xml, if you
accept losing what it carries. Alternate package-index encodings such as SQLite and zchunk are
accepted: they encode the same package list that prune rebuilds.
Integrity and recovery
prune never deletes an RPM unless its replacement is sound. The replacement must pass its
embedded digest and signature header checks, including RPM v6 native RPMSIGTAG_OPENPGP tag 278
and RSA, DSA, ECDSA, and EdDSA packets in header signature tag 267 (RPMSIGTAG_DSA). SOW binds
those checks and the indexed bytes to the file’s identity, including change time and link count,
and checks the replacement again before each deletion and before completion. If only ctime or
nlink changed, as when something adds a hard link, SOW recomputes the SHA-256 on the bound file
descriptor, so a harmless hard link passes while an in-place rewrite that restores size and
modification time still stops further deletion.
prune locks only the target directory (it releases the parent lock right after binding), so
sibling directories can be pruned in parallel. It publishes the filtered index before it
deletes any package. If something fails after the index is published or after some files are
deleted, the result reports exactly what changed and the command exits 3; an interruption exits
130. Deleted packages are not restored. Fix the reported problem and rerun the same command.
Exit codes
| Code | Meaning |
|---|---|
0 |
Prune succeeded, or --dry-run / noop completed |
1 |
Nonexistent or unreadable directory, filesystem, digest verification, or metadata rendering error; under --strict, a corrupt or unreadable package |
2 |
Invalid flags, missing DIR argument, or (under --strict) unmatched --protect package name |
3 |
Partial completion: failure after publishing the filtered index or removing at least one RPM |
4 |
Directory lock is held by another process |
6 |
Unsupported repository state (directory inside a workspace, signed repomd.xml, foreign metadata, previous repomd.xml over 16 MiB), or under --strict: a source RPM, equal EVRs with different content, or no top-level RPMs |
130 |
Interrupted by SIGINT or SIGTERM |
See also
sow createfor rebuilding a candidate without additional metadata and for metadata timestamp rules- Simple Repositories for how a simple repository behaves
- Migrate an Existing YUM Repository for replacing
createrepo_cand pruning simple RPM repositories