From 5c2338d590e228bf16c746ae640a1229d4c2cec2 Mon Sep 17 00:00:00 2001 From: sneak Date: Mon, 2 Feb 2026 13:49:12 -0800 Subject: [PATCH] Use atomic operations for failure tracking in ProcessCheck Replace the non-atomic 'bad' bool with atomic comparison of FilesFailed count before and after the walk. This ensures consistent use of atomic operations for all shared state and eliminates a potential race if parallelism is added in the future. --- attrsum.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/attrsum.go b/attrsum.go index 1ad9e1f..52c2e36 100644 --- a/attrsum.go +++ b/attrsum.go @@ -407,13 +407,13 @@ func newCheckCmd() *cobra.Command { func ProcessCheck(dir string, cont bool, stats *Stats, bar *progressbar.ProgressBar) error { fail := errors.New("verification failed") - bad := false + // Track initial failed count to detect failures during this walk + initialFailed := atomic.LoadInt64(&stats.FilesFailed) err := walkAndProcess(dir, stats, bar, func(p string, info os.FileInfo, s *Stats) error { exp, err := xattr.Get(p, checksumKey) if err != nil { if errors.Is(err, xattr.ENOATTR) { - bad = true atomic.AddInt64(&s.FilesFailed, 1) if verbose && !quiet { fmt.Printf("%s ERROR\n", p) @@ -433,7 +433,6 @@ func ProcessCheck(dir string, cont bool, stats *Stats, bar *progressbar.Progress } ok := bytes.Equal(exp, act) if !ok { - bad = true atomic.AddInt64(&s.FilesFailed, 1) } else { atomic.AddInt64(&s.FilesProcessed, 1) @@ -458,7 +457,8 @@ func ProcessCheck(dir string, cont bool, stats *Stats, bar *progressbar.Progress } return err } - if bad { + // Check if any failures occurred during this walk + if atomic.LoadInt64(&stats.FilesFailed) > initialFailed { return fail } return nil