author | Alberto Bertogli
<albertito@blitiri.com.ar> 2023-04-05 09:51:59 UTC |
committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2023-04-05 09:51:59 UTC |
parent | 5dc4f5969479df3f4d2c390e21a14f444a5e1091 |
summer.go | +7 | -7 |
test/basic.t | +19 | -10 |
test/sqlite.t | +3 | -3 |
ui.go | +18 | -8 |
diff --git a/summer.go b/summer.go index 40545ca..d7e04bc 100644 --- a/summer.go +++ b/summer.go @@ -163,7 +163,7 @@ func generate(db DB, root string) error { return err } - p.PrintNew(path) + p.PrintNew(path, csum) return nil } @@ -188,7 +188,7 @@ func verify(db DB, root string) error { return err } if !hasAttr { - p.PrintMissing(path) + p.PrintMissing(path, nil) return nil } @@ -209,11 +209,11 @@ func verify(db DB, root string) error { } if csumFromFile.ModTimeUsec != csumComputed.ModTimeUsec { - p.PrintModified(path) + p.PrintModified(path, csumFromFile, csumComputed) } else if csumFromFile.CRC32C != csumComputed.CRC32C { p.PrintCorrupted(path, csumFromFile, csumComputed) } else { - p.PrintMatched(path) + p.PrintMatched(path, csumComputed) } return nil @@ -258,7 +258,7 @@ func update(db DB, root string) error { } if !hasAttr { // Attribute is missing. Expected for newly created files. - p.PrintMissing(path) + p.PrintMissing(path, &csumComputed) return db.Write(fd, csumComputed) } @@ -269,12 +269,12 @@ func update(db DB, root string) error { if csumFromFile.ModTimeUsec != csumComputed.ModTimeUsec { // File modified. Expected for updated files. - p.PrintModified(path) + p.PrintModified(path, csumFromFile, csumComputed) return db.Write(fd, csumComputed) } else if csumFromFile.CRC32C != csumComputed.CRC32C { p.PrintCorrupted(path, csumFromFile, csumComputed) } else { - p.PrintMatched(path) + p.PrintMatched(path, csumComputed) } return nil diff --git a/test/basic.t b/test/basic.t index 124a812..b7abe63 100644 --- a/test/basic.t +++ b/test/basic.t @@ -68,29 +68,38 @@ But "generate" does override it. Check verbose and quiet. + $ touch denuevo $ summer -v verify . - "empty": match - "hola": match - "nueva": match - 0s: 3 matched, 0 modified, 0 new, 0 corrupted + "denuevo": missing checksum attribute + "empty": match \(checksum:0, mtime:\d+\) (re) + "hola": match \(checksum:\w+, mtime:\d+\) (re) + "nueva": match \(checksum:\w+, mtime:\d+\) (re) + 0s: 3 matched, 0 modified, 1 new, 0 corrupted + $ summer -v generate . + "denuevo": writing checksum \(checksum:\w+, mtime:\d+\) (re) + "empty": writing checksum \(checksum:0, mtime:\d+\) (re) + "hola": writing checksum \(checksum:\w+, mtime:\d+\) (re) + "nueva": writing checksum \(checksum:\w+, mtime:\d+\) (re) + 0s: 0 matched, 0 modified, 4 new, 0 corrupted $ summer -q verify . $ summer -q generate . $ summer -q update . $ summer -q verify . + $ rm denuevo Check that symlinks are ignored. $ ln -s hola thisisasymlink $ summer -v verify . - "empty": match - "hola": match - "nueva": match + "empty": match \(checksum:0, mtime:\d+\) (re) + "hola": match \(checksum:\w+, mtime:\d+\) (re) + "nueva": match \(checksum:\w+, mtime:\d+\) (re) 0s: 3 matched, 0 modified, 0 new, 0 corrupted Check that the root path doesn't confuse us. $ summer -v verify $PWD - "/.*/empty": match (re) - "/.*/hola": match (re) - "/.*/nueva": match (re) + "/.*/empty": match \(checksum:0, mtime:\d+\) (re) + "/.*/hola": match \(checksum:\w+, mtime:\d+\) (re) + "/.*/nueva": match \(checksum:\w+, mtime:\d+\) (re) 0s: 3 matched, 0 modified, 0 new, 0 corrupted diff --git a/test/sqlite.t b/test/sqlite.t index a011de9..35db2b5 100644 --- a/test/sqlite.t +++ b/test/sqlite.t @@ -19,9 +19,9 @@ This is enough to exercise the backend. Check that the root path doesn't confuse us. $ summer -db=db.sqlite3 -v verify $PWD - ".*/db.sqlite3": file modified \(not corrupted\), updating (re) - ".*/empty": match (re) - ".*/hola": match (re) + ".*/db.sqlite3": file modified \(not corrupted\) \(checksum: \w+ -> \w+, mtime: \d+ -> \d+\) (re) + ".*/empty": match \(checksum:0, mtime:\d+\) (re) + ".*/hola": match \(checksum:\w+, mtime:\d+\) (re) 0s: 2 matched, 1 modified, 0 new, 0 corrupted Force a write error to check it is appropriately handled. diff --git a/ui.go b/ui.go index b3442d0..e31eabb 100644 --- a/ui.go +++ b/ui.go @@ -124,30 +124,40 @@ func (p *Progress) PrintCorrupted(path string, expected, got ChecksumV1) { path, expected.CRC32C, got.CRC32C) } -func (p *Progress) PrintNew(path string) { +func (p *Progress) PrintNew(path string, cs ChecksumV1) { p.mu.Lock() defer p.mu.Unlock() p.missing++ - Verbosef("%q: adding checksum", path) + Verbosef("%q: writing checksum (checksum:%x, mtime:%d)", + path, cs.CRC32C, cs.ModTimeUsec) } -func (p *Progress) PrintMissing(path string) { +func (p *Progress) PrintMissing(path string, cs *ChecksumV1) { p.mu.Lock() defer p.mu.Unlock() p.missing++ - Verbosef("%q: missing checksum attribute, adding it", path) + if cs == nil { + Verbosef("%q: missing checksum attribute", path) + } else { + Verbosef("%q: missing checksum attribute, adding it "+ + "(checksum:%x, mtime:%d)", + path, cs.CRC32C, cs.ModTimeUsec) + } } -func (p *Progress) PrintModified(path string) { +func (p *Progress) PrintModified(path string, old, new_ ChecksumV1) { p.mu.Lock() defer p.mu.Unlock() p.modified++ - Verbosef("%q: file modified (not corrupted), updating", path) + Verbosef("%q: file modified (not corrupted) "+ + "(checksum: %x -> %x, mtime: %d -> %d)", + path, old.CRC32C, new_.CRC32C, old.ModTimeUsec, new_.ModTimeUsec) } -func (p *Progress) PrintMatched(path string) { +func (p *Progress) PrintMatched(path string, cs ChecksumV1) { p.mu.Lock() defer p.mu.Unlock() p.matched++ - Verbosef("%q: match", path) + Verbosef("%q: match (checksum:%x, mtime:%d)", + path, cs.CRC32C, cs.ModTimeUsec) }