diff --git a/check.go b/check.go index f72032f..90d5ca7 100644 --- a/check.go +++ b/check.go @@ -191,10 +191,17 @@ func checkFile(fn string) { } stats.outdated++ } + if !args.qq { printComparison(stored, actual) } - err = storeAttr(f, actual) + + // Only update the stored attribute if it is not corrupted **OR** + // if argument 'corruptupdate' been given. + if stored.ts != actual.ts || args.corruptupdate { + err = storeAttr(f, actual) + } + if err != nil { fmt.Fprintf(os.Stderr, "Error: %s\n", err) stats.errorsWritingXattr++ diff --git a/cshatag.1 b/cshatag.1 index d63ed2d..f54c291 100644 --- a/cshatag.1 +++ b/cshatag.1 @@ -47,15 +47,17 @@ rewritten in Go in 2019. .SH OPTIONS --dry-run don't make any changes +-dry-run don't make any changes .br --recursive recursively process the contents of directories +-recursive recursively process the contents of directories .br --remove remove cshatag's xattrs from FILE +-remove remove cshatag's xattrs from FILE .br --q quiet mode - don't report files +-q quiet mode - don't report files .br --qq quiet2 mode - only report files and errors +-qq quiet2 mode - only report files and errors +.br +-corruptupdate For any corrupted files found update the stored CRC .SH EXAMPLES diff --git a/main.go b/main.go index 4ed4026..a6ef150 100644 --- a/main.go +++ b/main.go @@ -25,11 +25,12 @@ var stats struct { } var args struct { - remove bool - recursive bool - q bool - qq bool - dryrun bool + remove bool + recursive bool + q bool + qq bool + dryrun bool + corruptupdate bool } // walkFn is used when `cshatag` is called with the `--recursive` option. It is the function called @@ -84,6 +85,7 @@ func main() { flag.BoolVar(&args.recursive, "recursive", false, "Recursively descend into subdirectories. "+ "Symbolic links are not followed.") flag.BoolVar(&args.dryrun, "dry-run", false, "don't make any changes") + flag.BoolVar(&args.corruptupdate, "corruptupdate", false, "For any corrupted files found update the stored CRC.") flag.Usage = func() { fmt.Fprintf(os.Stderr, "%s %s\n", myname, GitVersion) fmt.Fprintf(os.Stderr, "Usage: %s [OPTIONS] FILE [FILE2 ...]\n", myname)