Update golangci-lint to v2.12.2 with canonical config
All checks were successful
check / check (push) Successful in 32s
All checks were successful
check / check (push) Successful in 32s
- Replace .golangci.yml with the canonical v2-schema config: linter settings move under linters.settings (the previous top-level linters-settings block was ignored by golangci-lint v2, so the configured thresholds were not applied) and the obsolete issues.exclude-use-default key is dropped. - Bump golangci-lint from the v2.10.1-era commit pin to @v2.12.2 in Dockerfile and script/bootstrap; refresh pin date comments. - Wrap long lines in attrsum.go to satisfy the now-effective lll limit of 88 columns (15 findings); move one nolint:gosec directive to its own line. - Record the change in TODO.md Completed Steps.
This commit is contained in:
135
attrsum.go
135
attrsum.go
@@ -72,7 +72,8 @@ func (s *Stats) Print(opts *options, operation string) {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Fprintf(os.Stderr, "\n%s complete: %d files processed, %d skipped, %d failed, %s bytes in %s\n",
|
||||
fmt.Fprintf(os.Stderr,
|
||||
"\n%s complete: %d files processed, %d skipped, %d failed, %s bytes in %s\n",
|
||||
operation,
|
||||
s.FilesProcessed,
|
||||
s.FilesSkipped,
|
||||
@@ -166,11 +167,15 @@ func expandPaths(args []string) ([]string, error) {
|
||||
}
|
||||
|
||||
// processFunc processes a single path within a command's run loop.
|
||||
type processFunc func(opts *options, path string, stats *Stats, bar *progressbar.ProgressBar) error
|
||||
type processFunc func(
|
||||
opts *options, path string, stats *Stats, bar *progressbar.ProgressBar,
|
||||
) error
|
||||
|
||||
// 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) (*progressbar.ProgressBar, error) {
|
||||
func countAndBar(
|
||||
opts *options, paths []string, desc string,
|
||||
) (*progressbar.ProgressBar, error) {
|
||||
total, err := countFilesMultiple(opts, paths)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -188,7 +193,9 @@ func finishBar(bar *progressbar.ProgressBar) {
|
||||
|
||||
// runOverPaths runs process over each path, sharing the progress/stats
|
||||
// bookkeeping common to the sum-add, sum-update and clear commands.
|
||||
func runOverPaths(opts *options, args []string, desc, op string, process processFunc) error {
|
||||
func runOverPaths(
|
||||
opts *options, args []string, desc, op string, process processFunc,
|
||||
) error {
|
||||
paths, err := expandPaths(args)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -253,46 +260,54 @@ func newSumCmd(opts *options) *cobra.Command {
|
||||
return cmd
|
||||
}
|
||||
|
||||
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 {
|
||||
if hasXattr(p, checksumKey) {
|
||||
atomic.AddInt64(&s.FilesSkipped, 1)
|
||||
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 {
|
||||
if hasXattr(p, checksumKey) {
|
||||
atomic.AddInt64(&s.FilesSkipped, 1)
|
||||
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
err := writeChecksumAndTime(opts, p, info, s)
|
||||
if err != nil {
|
||||
atomic.AddInt64(&s.FilesFailed, 1)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
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 {
|
||||
t, err := readSumTime(p)
|
||||
if err != nil || info.ModTime().After(t) {
|
||||
werr := writeChecksumAndTime(opts, p, info, s)
|
||||
if werr != nil {
|
||||
err := writeChecksumAndTime(opts, p, info, s)
|
||||
if err != nil {
|
||||
atomic.AddInt64(&s.FilesFailed, 1)
|
||||
|
||||
return werr
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
atomic.AddInt64(&s.FilesSkipped, 1)
|
||||
|
||||
return nil
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func writeChecksumAndTime(opts *options, path string, info os.FileInfo, stats *Stats) error {
|
||||
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 {
|
||||
t, err := readSumTime(p)
|
||||
if err != nil || info.ModTime().After(t) {
|
||||
werr := writeChecksumAndTime(opts, p, info, s)
|
||||
if werr != nil {
|
||||
atomic.AddInt64(&s.FilesFailed, 1)
|
||||
|
||||
return werr
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
atomic.AddInt64(&s.FilesSkipped, 1)
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func writeChecksumAndTime(
|
||||
opts *options, path string, info os.FileInfo, stats *Stats,
|
||||
) error {
|
||||
// Record mtime before hashing to detect modifications during hash.
|
||||
mtimeBefore := info.ModTime()
|
||||
|
||||
@@ -363,24 +378,27 @@ 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 {
|
||||
cleared, err := clearOne(opts, p)
|
||||
if err != nil {
|
||||
atomic.AddInt64(&s.FilesFailed, 1)
|
||||
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 {
|
||||
cleared, err := clearOne(opts, p)
|
||||
if err != nil {
|
||||
atomic.AddInt64(&s.FilesFailed, 1)
|
||||
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
if cleared {
|
||||
atomic.AddInt64(&s.FilesProcessed, 1)
|
||||
atomic.AddInt64(&s.BytesProcessed, info.Size())
|
||||
} else {
|
||||
atomic.AddInt64(&s.FilesSkipped, 1)
|
||||
}
|
||||
if cleared {
|
||||
atomic.AddInt64(&s.FilesProcessed, 1)
|
||||
atomic.AddInt64(&s.BytesProcessed, info.Size())
|
||||
} else {
|
||||
atomic.AddInt64(&s.FilesSkipped, 1)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// clearOne removes both checksum xattrs from a single path, reporting
|
||||
@@ -428,7 +446,8 @@ func newCheckCmd(opts *options) *cobra.Command {
|
||||
return runCheck(opts, a, cont)
|
||||
},
|
||||
}
|
||||
cmd.Flags().BoolVar(&cont, "continue", false, "continue after errors and report each file")
|
||||
cmd.Flags().BoolVar(&cont, "continue", false,
|
||||
"continue after errors and report each file")
|
||||
|
||||
return cmd
|
||||
}
|
||||
@@ -472,13 +491,16 @@ func runCheck(opts *options, args []string, cont bool) error {
|
||||
return finalErr
|
||||
}
|
||||
|
||||
func processCheck(opts *options, dir string, cont bool, stats *Stats, bar *progressbar.ProgressBar) error {
|
||||
func processCheck(
|
||||
opts *options, dir string, cont bool, stats *Stats, bar *progressbar.ProgressBar,
|
||||
) error {
|
||||
// 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 {
|
||||
return checkOne(opts, p, cont, s)
|
||||
})
|
||||
err := walkAndProcess(opts, dir, stats, bar,
|
||||
func(p string, _ os.FileInfo, s *Stats) error {
|
||||
return checkOne(opts, p, cont, s)
|
||||
})
|
||||
if err != nil {
|
||||
if errors.Is(err, errVerification) {
|
||||
return errVerification
|
||||
@@ -742,7 +764,8 @@ func hasXattr(path, key string) bool {
|
||||
func fileMultihash(path string) ([]byte, int64, error) {
|
||||
// The path is supplied by the operator as the tree to checksum; reading
|
||||
// it is the entire purpose of the tool.
|
||||
f, err := os.Open(path) //nolint:gosec // G304: operator-specified path is the intended input
|
||||
//nolint:gosec // G304: operator-specified path is the intended input
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user