From 61204c6bba4eaef75daac2441f1df28642964b0d Mon Sep 17 00:00:00 2001 From: kapitainsky Date: Tue, 21 Nov 2023 17:05:09 +0000 Subject: [PATCH 1/2] '-corruptupdate' will update the CRC of any corrupted files "I have added one argument/option '-corruptupdate' which when used will update the CRC of any corrupted files (i.e. the current default behaviour). Without this option the code doesn't update the attribute/CRC and subsequent runs of the code will still show the file as corrupt. I have done it this way as in my view a corrupted file should remain flagged as corrupt until fixed (or some other actions is taken)." Source: https://github.com/rfjakob/cshatag/issues/26#issuecomment-1510374260 There is one problem with not updating the checksum: You will not notice when the file gets corrupted again (unless you compare the checksum). Yes, however if the file is already corrupt, any further corruption is irrelevant until it is fixed. The way I see this working, with the patch, is thus: Case 1 - no action I run cshatag It detects a corrupt file. I do nothing at all I run cshatag The corrupt file is still flagged. Case 2 - fixing the corrupt file I run cshatag It detects a corrupt file. I fix the file and then on this file only... I run cshatag -corruptupdate - that will update the file and should no longer flag as corrupt. File is fixed, no longer shows as corrupt on further cshatag runs. Others will until they are fixed. That way any corruption will show on every run until such time as I specifically tell it to update the file, i.e. I have fixed it. --- check.go | 9 ++++++++- main.go | 12 +++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) 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/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) From ddd15033be3334caf12afd5011152a7adb94abee Mon Sep 17 00:00:00 2001 From: kapitainsky Date: Tue, 21 Nov 2023 19:38:27 +0000 Subject: [PATCH 2/2] Update man page --- cshatag.1 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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