Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af36c94f91 |
+10
-14
@@ -179,9 +179,9 @@ type processFunc func(
|
||||
// countAndBar counts the files under paths and returns a progress bar sized
|
||||
// to that total. It always returns either a non-nil bar or a non-nil error.
|
||||
func countAndBar(
|
||||
opts *options, paths []string, desc string, cont bool,
|
||||
opts *options, paths []string, desc string,
|
||||
) (*progressbar.ProgressBar, error) {
|
||||
total, err := countFilesMultiple(opts, paths, cont)
|
||||
total, err := countFilesMultiple(opts, paths)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -211,7 +211,7 @@ func runOverPaths(
|
||||
var bar *progressbar.ProgressBar
|
||||
|
||||
if !opts.quiet {
|
||||
bar, err = countAndBar(opts, paths, desc, false)
|
||||
bar, err = countAndBar(opts, paths, desc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -468,8 +468,10 @@ func runCheck(opts *options, args []string, cont bool) error {
|
||||
var bar *progressbar.ProgressBar
|
||||
|
||||
if !opts.quiet {
|
||||
bar, err = countAndBar(opts, paths, "Verifying checksums", cont)
|
||||
if err != nil {
|
||||
// With --continue, a path the count cannot read leaves the run
|
||||
// without a progress bar; the walk below reports it as failed.
|
||||
bar, err = countAndBar(opts, paths, "Verifying checksums")
|
||||
if err != nil && !cont {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -605,18 +607,12 @@ func reportCheck(opts *options, p, actual string, ok bool) {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// countFiles counts the total number of regular files that will be processed.
|
||||
// With cont, a path it cannot read is left out of the count instead of ending
|
||||
// it; the walk that follows reports that path as failed.
|
||||
func countFiles(opts *options, root string, cont bool) (int64, error) {
|
||||
func countFiles(opts *options, root string) (int64, error) {
|
||||
var count int64
|
||||
|
||||
root = filepath.Clean(root)
|
||||
|
||||
err := filepath.Walk(root, func(p string, info os.FileInfo, err error) error {
|
||||
if err != nil && cont {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -651,11 +647,11 @@ func countFiles(opts *options, root string, cont bool) (int64, error) {
|
||||
}
|
||||
|
||||
// countFilesMultiple counts files across multiple roots.
|
||||
func countFilesMultiple(opts *options, roots []string, cont bool) (int64, error) {
|
||||
func countFilesMultiple(opts *options, roots []string) (int64, error) {
|
||||
var total int64
|
||||
|
||||
for _, root := range roots {
|
||||
count, err := countFiles(opts, root, cont)
|
||||
count, err := countFiles(opts, root)
|
||||
if err != nil {
|
||||
return total, err
|
||||
}
|
||||
|
||||
@@ -319,12 +319,4 @@ func TestCheckContinuePastUnreadable(t *testing.T) {
|
||||
t.Fatalf("expected 2 verified and 2 failed, got %d and %d",
|
||||
stats.FilesProcessed, stats.FilesFailed)
|
||||
}
|
||||
|
||||
// Without --quiet, runCheck counts the files for the progress bar
|
||||
// before it checks any, so the count reaches the unlistable directory
|
||||
// first.
|
||||
err = runCheck(opts, []string{dir}, true)
|
||||
if !errors.Is(err, errVerification) {
|
||||
t.Fatalf("expected verification error from runCheck, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user