check / check (push) Waiting to run
sfdupes dwim, as sneak ordered: with no arguments it runs what scan / runs with no flags, default excludes on, then what trees runs, printing the duplicate trees largest first on stdout. Its last line, on stderr, says that sfdupes trees prints the report again. It needs no setup beyond what scan creates. SIGINT or SIGTERM during the scan stops it as it stops scan, exit 1, with no report; during the report a signal ends it at once, as it ends trees. A positional argument is a usage error, exit 2. Model: opus-5-5
38 lines
917 B
Go
38 lines
917 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"runtime"
|
|
)
|
|
|
|
// runDwim implements the dwim subcommand: it runs what "sfdupes scan
|
|
// root" runs with no flags, then what "sfdupes trees" runs, and ends
|
|
// with a line on stderr saying how to print the report again. The dwim
|
|
// command passes "/" as root. It catches SIGINT and SIGTERM as scan
|
|
// does, but only during the scan. An error from the scan, an interrupt
|
|
// included, ends it before the report. During the report, a signal
|
|
// ends it at once, as it ends trees.
|
|
func runDwim(ctx context.Context, root string, stdout io.Writer) error {
|
|
scanCtx, stop := interruptContext(ctx)
|
|
err := runScan(scanCtx, []string{root}, runtime.NumCPU(), false, false)
|
|
|
|
stop()
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = runTrees(ctx, stdout)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Fprintln(os.Stderr,
|
|
`dwim: run "sfdupes trees" to print this report again`)
|
|
|
|
return nil
|
|
}
|