diff --git a/internal/cli/gen.go b/internal/cli/gen.go index 47a32cf..310d7df 100644 --- a/internal/cli/gen.go +++ b/internal/cli/gen.go @@ -2,8 +2,11 @@ package cli import ( "fmt" + "os" + "os/signal" "path/filepath" "sync" + "syscall" "time" "github.com/dustin/go-humanize" @@ -84,9 +87,24 @@ func (mfa *CLIApp) generateManifestOperation(ctx *cli.Context) error { return fmt.Errorf("failed to create temp file: %w", err) } + // Set up signal handler to clean up temp file on Ctrl-C + sigChan := make(chan os.Signal, 1) + signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM) + go func() { + sig, ok := <-sigChan + if !ok || sig == nil { + return // Channel closed normally, not a signal + } + _ = outFile.Close() + _ = mfa.Fs.Remove(tmpPath) + os.Exit(1) + }() + // Clean up temp file on any error or interruption success := false defer func() { + signal.Stop(sigChan) + close(sigChan) _ = outFile.Close() if !success { _ = mfa.Fs.Remove(tmpPath) diff --git a/internal/scanner/scanner.go b/internal/scanner/scanner.go index d290a76..f286ebd 100644 --- a/internal/scanner/scanner.go +++ b/internal/scanner/scanner.go @@ -10,6 +10,7 @@ import ( "sync" "time" + "github.com/dustin/go-humanize" "github.com/spf13/afero" "sneak.berlin/go/mfer/internal/log" "sneak.berlin/go/mfer/mfer" @@ -354,7 +355,7 @@ func (s *Scanner) ToManifest(ctx context.Context, w io.Writer, progress chan<- S return err } - log.Verbosef("+ %s (%d bytes)", entry.Path, bytesRead) + log.Verbosef("+ %s (%s)", entry.Path, humanize.IBytes(uint64(bytesRead))) scannedFiles++ scannedBytes += bytesRead