Handle every error return flagged by golangci-lint's errcheck rather than discarding it: - run.go: add a cleanup() helper that logs a warning (and ignores ErrNotExist) when removing a temp file fails, so leaked scratch files are surfaced; use it for all best-effort removals. - copy.go / extract.go: log a warning on deferred Close() failures for the source file, destination DB, and result-set rows. - extract.go: on the rollback path, ignore the benign sql.ErrTxDone (already committed) and log any other rollback failure. - verify.go: add killCat() which ignores os.ErrProcessDone (zstdcat already exited via SIGPIPE) and logs any unexpected kill failure. make check is clean (0 lint issues, tests pass).
This commit is contained in:
@@ -1,12 +1,26 @@
|
||||
package bsdaily
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// killCat terminates the zstdcat process, ignoring the benign case where it
|
||||
// has already exited (e.g. after receiving SIGPIPE when head closed the pipe)
|
||||
// and logging any other failure.
|
||||
func killCat(cmd *exec.Cmd) {
|
||||
if cmd.Process == nil {
|
||||
return
|
||||
}
|
||||
if err := cmd.Process.Kill(); err != nil && !errors.Is(err, os.ErrProcessDone) {
|
||||
slog.Warn("failed to kill zstdcat process", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func VerifyOutput(path string) error {
|
||||
slog.Info("running zstdmt integrity check")
|
||||
testCmd := exec.Command("zstdmt", "--test", path)
|
||||
@@ -34,18 +48,18 @@ func VerifyOutput(path string) error {
|
||||
return fmt.Errorf("starting zstdcat: %w", err)
|
||||
}
|
||||
if err := headCmd.Start(); err != nil {
|
||||
catCmd.Process.Kill() // Clean up if head fails to start
|
||||
killCat(catCmd) // Clean up if head fails to start
|
||||
return fmt.Errorf("starting head: %w", err)
|
||||
}
|
||||
|
||||
// Wait for head first (it will exit when it has enough lines)
|
||||
if err := headCmd.Wait(); err != nil {
|
||||
catCmd.Process.Kill()
|
||||
killCat(catCmd)
|
||||
return fmt.Errorf("head command failed: %w", err)
|
||||
}
|
||||
|
||||
// Kill zstdcat since head closed the pipe (expected SIGPIPE)
|
||||
catCmd.Process.Kill()
|
||||
killCat(catCmd)
|
||||
_ = catCmd.Wait() // Reap the process
|
||||
|
||||
content := headOut.String()
|
||||
|
||||
Reference in New Issue
Block a user