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:
2025-12-17 14:30:10 -08:00
parent fded1a0393
commit c5ca3e2ced
11 changed files with 1459 additions and 67 deletions

View File

@@ -2,20 +2,58 @@ package cli
import (
"fmt"
"path/filepath"
"time"
"github.com/spf13/afero"
"github.com/urfave/cli/v2"
"sneak.berlin/go/mfer/internal/checker"
"sneak.berlin/go/mfer/internal/log"
)
// findManifest looks for a manifest file in the given directory.
// It checks for index.mf and .index.mf, returning the first one found.
func findManifest(fs afero.Fs, dir string) (string, error) {
candidates := []string{"index.mf", ".index.mf"}
for _, name := range candidates {
path := filepath.Join(dir, name)
exists, err := afero.Exists(fs, path)
if err != nil {
return "", err
}
if exists {
return path, nil
}
}
return "", fmt.Errorf("no manifest found in %s (looked for index.mf and .index.mf)", dir)
}
func (mfa *CLIApp) checkManifestOperation(ctx *cli.Context) error {
log.Debug("checkManifestOperation()")
// Get manifest path from args, default to index.mf
manifestPath := "index.mf"
var manifestPath string
var err error
if ctx.Args().Len() > 0 {
manifestPath = ctx.Args().Get(0)
arg := ctx.Args().Get(0)
// Check if arg is a directory or a file
info, statErr := mfa.Fs.Stat(arg)
if statErr == nil && info.IsDir() {
// It's a directory, look for manifest inside
manifestPath, err = findManifest(mfa.Fs, arg)
if err != nil {
return err
}
} else {
// Treat as a file path
manifestPath = arg
}
} else {
// No argument, look in current directory
manifestPath, err = findManifest(mfa.Fs, ".")
if err != nil {
return err
}
}
basePath := ctx.String("base")
@@ -40,10 +78,20 @@ func (mfa *CLIApp) checkManifestOperation(ctx *cli.Context) error {
progress = make(chan checker.CheckStatus, 1)
go func() {
for status := range progress {
log.Progressf("Checking: %d/%d files, %d failures",
status.CheckedFiles,
status.TotalFiles,
status.Failures)
if status.ETA > 0 {
log.Progressf("Checking: %d/%d files, %.1f MB/s, ETA %s, %d failures",
status.CheckedFiles,
status.TotalFiles,
status.BytesPerSec/1e6,
status.ETA.Round(time.Second),
status.Failures)
} else {
log.Progressf("Checking: %d/%d files, %.1f MB/s, %d failures",
status.CheckedFiles,
status.TotalFiles,
status.BytesPerSec/1e6,
status.Failures)
}
}
log.ProgressDone()
}()