Change FileProgress callback to channel-based progress
Replace callback-based progress reporting in Builder.AddFile with channel-based FileHashProgress for consistency with EnumerateStatus and ScanStatus patterns. Update scanner.go to use the new channel API.
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/afero"
|
||||
"github.com/urfave/cli/v2"
|
||||
"sneak.berlin/go/mfer/internal/log"
|
||||
"sneak.berlin/go/mfer/internal/scanner"
|
||||
@@ -62,8 +63,15 @@ func (mfa *CLIApp) generateManifestOperation(ctx *cli.Context) error {
|
||||
|
||||
log.Debugf("enumerated %d files, %d bytes total", s.FileCount(), s.TotalBytes())
|
||||
|
||||
// Open output file
|
||||
// Check if output file exists
|
||||
outputPath := ctx.String("output")
|
||||
if exists, _ := afero.Exists(mfa.Fs, outputPath); exists {
|
||||
if !ctx.Bool("force") {
|
||||
return fmt.Errorf("output file %s already exists (use --force to overwrite)", outputPath)
|
||||
}
|
||||
}
|
||||
|
||||
// Open output file
|
||||
outFile, err := mfa.Fs.Create(outputPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create output file: %w", err)
|
||||
@@ -76,10 +84,18 @@ func (mfa *CLIApp) generateManifestOperation(ctx *cli.Context) error {
|
||||
scanProgress = make(chan scanner.ScanStatus, 1)
|
||||
go func() {
|
||||
for status := range scanProgress {
|
||||
log.Progressf("Scanning: %d/%d files, %.1f MB/s",
|
||||
status.ScannedFiles,
|
||||
status.TotalFiles,
|
||||
status.BytesPerSec/1e6)
|
||||
if status.ETA > 0 {
|
||||
log.Progressf("Scanning: %d/%d files, %.1f MB/s, ETA %s",
|
||||
status.ScannedFiles,
|
||||
status.TotalFiles,
|
||||
status.BytesPerSec/1e6,
|
||||
status.ETA.Round(time.Second))
|
||||
} else {
|
||||
log.Progressf("Scanning: %d/%d files, %.1f MB/s",
|
||||
status.ScannedFiles,
|
||||
status.TotalFiles,
|
||||
status.BytesPerSec/1e6)
|
||||
}
|
||||
}
|
||||
log.ProgressDone()
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user