aboutsummaryrefslogtreecommitdiff
path: root/internal/scan
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 21:43:23 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 21:43:23 +0200
commitc497d173b24b1b8247fac9e996e5c0fe690c1769 (patch)
tree2318ff1cf393e3a6c2a7d54c89e205ac6a9a5c73 /internal/scan
parent360591d6e18d8676a2f86185ed42f46852387f85 (diff)
downloadkrino-c497d173b24b1b8247fac9e996e5c0fe690c1769.tar.gz
krino-c497d173b24b1b8247fac9e996e5c0fe690c1769.zip
plan 9: undo review matches review, --min-age validated, future mtimes, rule names, conflict enum, dependency gate, absolute tool paths
Diffstat (limited to 'internal/scan')
-rw-r--r--internal/scan/scan.go12
-rw-r--r--internal/scan/scan_test.go21
2 files changed, 32 insertions, 1 deletions
diff --git a/internal/scan/scan.go b/internal/scan/scan.go
index 77cca66..bd717e0 100644
--- a/internal/scan/scan.go
+++ b/internal/scan/scan.go
@@ -229,7 +229,7 @@ func (w *walker) walk(dir, relDir string, depth int, entries []os.DirEntry) erro
w.result.Skipped = append(w.result.Skipped, Skipped{Rel: rel, Reason: Busy})
continue
}
- if w.opt.Now.Sub(info.ModTime()) < w.opt.MinAge {
+ if Age(w.opt.Now, info.ModTime()) < w.opt.MinAge {
w.result.Skipped = append(w.result.Skipped, Skipped{Rel: rel, Reason: TooNew})
continue
}
@@ -252,3 +252,13 @@ func (w *walker) isBusy(name string, names map[string]bool) bool {
}
return false
}
+
+// Age is how long ago mtime was, at now. A modification time ahead of the
+// clock (a skewed server, an archive's timestamps) counts as brand new: age
+// 0, so min-age 0 still considers the file (review cli F5).
+func Age(now, mtime time.Time) time.Duration {
+ if a := now.Sub(mtime); a > 0 {
+ return a
+ }
+ return 0
+}
diff --git a/internal/scan/scan_test.go b/internal/scan/scan_test.go
index e9aeb73..35e7a0d 100644
--- a/internal/scan/scan_test.go
+++ b/internal/scan/scan_test.go
@@ -319,3 +319,24 @@ func TestFilesCarryInode(t *testing.T) {
t.Errorf("rename changed the identity: %+v then %+v", first.Files[0], second.Files)
}
}
+
+// TestFutureFileIsNotTooNewAtMinAgeZero: a file whose modification time is
+// ahead of the clock counts as brand new - skipped while min-age is above
+// zero, considered at min-age 0 (review cli F5).
+func TestFutureFileIsNotTooNewAtMinAgeZero(t *testing.T) {
+ root := tree(t)
+ p := filepath.Join(root, "future.txt")
+ if err := os.WriteFile(p, []byte("x"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ ahead := now.Add(time.Hour)
+ if err := os.Chtimes(p, ahead, ahead); err != nil {
+ t.Fatal(err)
+ }
+ if r, _ := Walk(root, Options{Now: now}); len(rels(r)) != 1 {
+ t.Errorf("min-age 0: files %v, skipped %v; want future.txt considered", rels(r), skipped(r))
+ }
+ if r, _ := Walk(root, Options{Now: now, MinAge: time.Minute}); skipped(r)["future.txt"] != TooNew {
+ t.Errorf("min-age 1m: skipped %v; want future.txt too new", skipped(r))
+ }
+}