git » summer » commit 1505ca2

Print checksum mtime on corrupted files

author Alberto Bertogli
2025-04-13 09:20:19 UTC
committer Alberto Bertogli
2025-04-13 09:20:19 UTC
parent e6fa249fd730eb720bff392c05228f1322bda3bc

Print checksum mtime on corrupted files

When a file is corrupted, it can be useful to know the checksum mtime
for debugging purposes.

Today, summer doesn't show it, so this patch adds it to the information
printed when a file is corrupted.

It now prints the epoch as well as the parsed time, for extra
convenience.

test/basic.t +2 -2
ui.go +3 -2

diff --git a/test/basic.t b/test/basic.t
index d79bce7..84f365d 100644
--- a/test/basic.t
+++ b/test/basic.t
@@ -36,7 +36,7 @@ Corrupt a file by changing its contents without changing the mtime.
   $ touch --date="$OLD_MTIME" hola
 
   $ summer verify .
-  "hola": FILE CORRUPTED - expected:239059f6, got:916db13f
+  "hola": FILE CORRUPTED - expected: 239059f6, got: 916db13f \(mtime: \d+\ = [\dTZ.:-]+\) (re)
   0s: 2 matched, 0 modified, 0 new, 1 corrupted
   detected 1 corrupted files
   [1]
@@ -45,7 +45,7 @@ Check that "update" also detects the corruption, and doesn't just step over
 it.
 
   $ summer update .
-  "hola": FILE CORRUPTED - expected:239059f6, got:916db13f
+  "hola": FILE CORRUPTED - expected: 239059f6, got: 916db13f \(mtime: \d+\ = [\dTZ.:-]+\) (re)
   0s: 2 matched, 0 modified, 0 new, 1 corrupted
   detected 1 corrupted files
   [1]
diff --git a/ui.go b/ui.go
index 72d228e..ef86afa 100644
--- a/ui.go
+++ b/ui.go
@@ -137,8 +137,9 @@ func (p *Progress) PrintCorrupted(path string, expected, got ChecksumV1) {
 	p.mu.Lock()
 	defer p.mu.Unlock()
 	p.corrupted++
-	Printf("%q: FILE CORRUPTED - expected:%x, got:%x",
-		path, expected.CRC32C, got.CRC32C)
+	Printf("%q: FILE CORRUPTED - expected: %x, got: %x (mtime: %d = %s)",
+		path, expected.CRC32C, got.CRC32C, got.ModTimeUsec,
+		time.UnixMicro(got.ModTimeUsec).Format(time.RFC3339Nano))
 }
 
 func (p *Progress) PrintNew(path string, cs ChecksumV1) {