Stop scan cleanly on SIGINT or SIGTERM (closes #5)
check / check (push) Waiting to run

A first SIGINT or SIGTERM cancels the scan. It commits the hashed
records still in its batch, with a context that is not cancelled for
that one write, and starts no other write or deletion; deletions need
a complete walk, so records under paths an interrupted walk never
reached are kept. A batch whose commit failed is now kept for that
final commit instead of dropped. The progress display is finished (a
bar stopped short is no longer filled up), `scan: interrupted after N
files` goes to stderr, and the exit code is 1. A second signal ends the
process at once. A SIGINT inherited as ignored stays ignored.

Model: opus-5-5
This commit was merged in pull request #79.
This commit is contained in:
2026-10-04 09:30:38 +02:00
parent 33cf3dd29a
commit 4847882e46
8 changed files with 446 additions and 62 deletions
+6
View File
@@ -87,6 +87,9 @@ func run(args []string, stdout, stderr io.Writer) int {
switch {
case err == nil:
return exitOK
case errors.Is(err, errInterrupted):
// The interrupted scan has printed its own line.
return exitFatal
case errors.As(err, &fatal):
// The command ran and failed: a runtime error, reported
// without the usage text that a usage error gets.
@@ -132,6 +135,9 @@ func newRootCommand(stdout, stderr io.Writer) *cobra.Command {
Short: "Walk trees and synchronize the scan database",
Args: cobra.MinimumNArgs(1),
RunE: runE(func(ctx context.Context, args []string) error {
ctx, stop := interruptContext(ctx)
defer stop()
return runScan(ctx, args, scanWorkers, scanOneFS)
}),
}