Keep going past unreadable files with check --continue (closes #11)
check / check (push) Successful in 3m59s
check / check (push) Successful in 3m59s
With --continue, check stopped at the first file whose content or checksum attribute it could not read, and at the first directory it could not list. Each of these now counts as failed, its error, which names the path, goes to stderr, and the walk goes on; the run still exits non-zero. The walk shared with sum and clear takes the continue setting, and they pass false. If the count that sizes the progress bar cannot read a path, check --continue runs without the bar. Without --continue the first such error still stops the run, and the summary printed before it now counts an unreadable checksum attribute as failed, as it already did for unreadable content. Model: opus-5-5
This commit is contained in:
+26
-10
@@ -259,7 +259,7 @@ func newSumCmd(opts *options) *cobra.Command {
|
||||
}
|
||||
|
||||
func processSumAdd(opts *options, dir string, stats *Stats, bar *progressbar.ProgressBar) error {
|
||||
return walkAndProcess(opts, dir, stats, bar, func(p string, info os.FileInfo, s *Stats) error {
|
||||
return walkAndProcess(opts, dir, false, stats, bar, func(p string, info os.FileInfo, s *Stats) error {
|
||||
if hasXattr(p, checksumKey) {
|
||||
atomic.AddInt64(&s.FilesSkipped, 1)
|
||||
|
||||
@@ -278,7 +278,7 @@ func processSumAdd(opts *options, dir string, stats *Stats, bar *progressbar.Pro
|
||||
}
|
||||
|
||||
func processSumUpdate(opts *options, dir string, stats *Stats, bar *progressbar.ProgressBar) error {
|
||||
return walkAndProcess(opts, dir, stats, bar, func(p string, info os.FileInfo, s *Stats) error {
|
||||
return walkAndProcess(opts, dir, false, stats, bar, func(p string, info os.FileInfo, s *Stats) error {
|
||||
t, err := readSumTime(p)
|
||||
if err != nil || info.ModTime().After(t) {
|
||||
werr := writeChecksumAndTime(opts, p, info, s)
|
||||
@@ -369,7 +369,7 @@ func newClearCmd(opts *options) *cobra.Command {
|
||||
}
|
||||
|
||||
func processClear(opts *options, dir string, stats *Stats, bar *progressbar.ProgressBar) error {
|
||||
return walkAndProcess(opts, dir, stats, bar, func(p string, info os.FileInfo, s *Stats) error {
|
||||
return walkAndProcess(opts, dir, false, stats, bar, func(p string, info os.FileInfo, s *Stats) error {
|
||||
cleared, err := clearOne(opts, p)
|
||||
if err != nil {
|
||||
atomic.AddInt64(&s.FilesFailed, 1)
|
||||
@@ -449,8 +449,10 @@ func runCheck(opts *options, args []string, cont bool) error {
|
||||
var bar *progressbar.ProgressBar
|
||||
|
||||
if !opts.quiet {
|
||||
// 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 {
|
||||
if err != nil && !cont {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -481,7 +483,7 @@ func processCheck(opts *options, dir string, cont bool, stats *Stats, bar *progr
|
||||
// Track initial failed count to detect failures during this walk.
|
||||
initialFailed := atomic.LoadInt64(&stats.FilesFailed)
|
||||
|
||||
err := walkAndProcess(opts, dir, stats, bar, func(p string, _ os.FileInfo, s *Stats) error {
|
||||
err := walkAndProcess(opts, dir, cont, stats, bar, func(p string, _ os.FileInfo, s *Stats) error {
|
||||
return checkOne(opts, p, cont, s)
|
||||
})
|
||||
if err != nil {
|
||||
@@ -505,7 +507,7 @@ func checkOne(opts *options, p string, cont bool, s *Stats) error {
|
||||
exp, err := xattr.Get(p, checksumKey)
|
||||
if err != nil {
|
||||
if !errors.Is(err, xattr.ENOATTR) {
|
||||
return err
|
||||
return unreadable(cont, s, err)
|
||||
}
|
||||
|
||||
return missingChecksum(opts, p, cont, s)
|
||||
@@ -513,9 +515,7 @@ func checkOne(opts *options, p string, cont bool, s *Stats) error {
|
||||
|
||||
act, bytesRead, err := fileMultihash(p)
|
||||
if err != nil {
|
||||
atomic.AddInt64(&s.FilesFailed, 1)
|
||||
|
||||
return err
|
||||
return unreadable(cont, s, err)
|
||||
}
|
||||
|
||||
ok := bytes.Equal(exp, act)
|
||||
@@ -551,6 +551,21 @@ func missingChecksum(opts *options, p string, cont bool, s *Stats) error {
|
||||
return errVerification
|
||||
}
|
||||
|
||||
// unreadable counts a file or directory that could not be read as failed.
|
||||
// With --continue it prints err, which names the path, to stderr and
|
||||
// returns nil so the walk goes on; otherwise it returns err.
|
||||
func unreadable(cont bool, s *Stats, err error) error {
|
||||
atomic.AddInt64(&s.FilesFailed, 1)
|
||||
|
||||
if !cont {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Print(err)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// reportCheck prints a per-file verification result when verbose output is on.
|
||||
func reportCheck(opts *options, p, actual string, ok bool) {
|
||||
if !opts.verbose || opts.quiet {
|
||||
@@ -650,6 +665,7 @@ func newProgressBar(total int64, description string) *progressbar.ProgressBar {
|
||||
func walkAndProcess(
|
||||
opts *options,
|
||||
root string,
|
||||
cont bool,
|
||||
stats *Stats,
|
||||
bar *progressbar.ProgressBar,
|
||||
fn func(string, os.FileInfo, *Stats) error,
|
||||
@@ -658,7 +674,7 @@ func walkAndProcess(
|
||||
|
||||
return filepath.Walk(root, func(p string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
return unreadable(cont, stats, err)
|
||||
}
|
||||
|
||||
skip, skipErr := walkSkip(opts, root, p, info)
|
||||
|
||||
Reference in New Issue
Block a user