Gate prune's local-cleanup output on --json, and make make build build (closes #108)
check / check (push) Successful in 2m16s
check / check (push) Successful in 2m16s
Closes #110. CleanupLocalSnapshots wrote three prose lines to stdout with no --json awareness, covering every branch, so `vaultik prune --json | jq` failed on any input. -q never helped either: printlnStdout and stdoutf write straight to v.Stdout and never consult v.UI, which is what SetQuiet affects. It now takes *PruneOptions, symmetric with its sibling phase PruneBlobs, and gates all three writes. Threading opts.JSON was chosen over moving the lines to log.Info, because internal/log/log.go defaults the level to Warn: log.Info would not have relocated them to stderr, it would have deleted them from a plain `vaultik prune`, and "Removing stale local record" narrates the deletion of local index rows. The stale-record count is deliberately not added to PruneBlobsResult - every field there is blob-scoped and produced by the phase that runs after this reconciliation, so adding it would change a published --json schema as a side effect of a stream fix. Note for anyone reading the --json contract: under --json the stale-record removal now produces no signal in either stream. stdout is correctly gated, stderr is level-pinned to Warn because --json sets Quiet, and the count is not in the document. That is inherited behaviour - PruneBlobs' own log.Info calls are equally invisible under --json - not something this change introduced, and it is tracked separately. make build exited 0 and produced nothing: .PHONY listed build with no build: rule, and a phony target with no prerequisites and no recipe is considered already satisfied, which turns what would be a hard error into a silent success. In a repo where `make build` is the documented way to build, a caller checking the exit code concluded the build worked. Now `build: vaultik`, verified in both directions - a clean build produces the binary, a deliberately broken one exits non-zero and produces none. All 19 .PHONY names were audited; build was the only one lacking a rule. TestPhonyTargetsAllHaveRules keeps that true for names added later, so the class is closed rather than the instance.
This commit was merged in pull request #111.
This commit is contained in:
@@ -829,7 +829,15 @@ func (v *Vaultik) outputVerifyJSON(result *VerifyResult) error {
|
||||
// behind by incomplete or interrupted backups. Each local snapshot's
|
||||
// human ID is hashed via RemoteSnapshotKey and compared against the
|
||||
// remote listing.
|
||||
func (v *Vaultik) CleanupLocalSnapshots() error {
|
||||
//
|
||||
// It takes the whole *PruneOptions, symmetric with PruneBlobs, because
|
||||
// it is the other half of one command: Prune runs this phase and then
|
||||
// that one. Only JSON is read here. Under --json every write below is
|
||||
// suppressed, because stdout carries the PruneBlobsResult document and
|
||||
// nothing else — prose ahead of it is what made `vaultik prune --json |
|
||||
// jq` fail (issue #108). The narration is duplicated as log records,
|
||||
// which go to stderr and so cannot corrupt the document.
|
||||
func (v *Vaultik) CleanupLocalSnapshots(opts *PruneOptions) error {
|
||||
err := v.EnsureStorageBinding()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -855,7 +863,11 @@ func (v *Vaultik) CleanupLocalSnapshots() error {
|
||||
for _, snap := range localSnapshots {
|
||||
id := snap.ID.String()
|
||||
if !remoteSet[snapshot.RemoteSnapshotKey(id)] {
|
||||
v.stdoutf("Removing stale local record: %s\n", id)
|
||||
log.Info("Removing stale local snapshot record", "snapshot_id", id)
|
||||
|
||||
if !opts.JSON {
|
||||
v.stdoutf("Removing stale local record: %s\n", id)
|
||||
}
|
||||
|
||||
err = v.deleteSnapshotFromLocalDB(id)
|
||||
if err != nil {
|
||||
@@ -869,6 +881,13 @@ func (v *Vaultik) CleanupLocalSnapshots() error {
|
||||
}
|
||||
}
|
||||
|
||||
log.Info("Reconciled local snapshot records against remote metadata",
|
||||
"removed", removed, "examined", len(localSnapshots))
|
||||
|
||||
if opts.JSON {
|
||||
return nil
|
||||
}
|
||||
|
||||
if removed == 0 {
|
||||
v.printlnStdout("No stale local snapshots found.")
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user