aboutsummaryrefslogtreecommitdiff
path: root/cmd/krino/sort_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-15 00:26:36 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-15 00:26:36 +0200
commitf12f3f1356e4e96d419d66d13c2e67b73a50346f (patch)
treec3d83c41030b0fae8252cc18783c40fa9c8d0f9d /cmd/krino/sort_test.go
parent8a046c897e42e9459aa99377589c80c773601efc (diff)
downloadkrino-f12f3f1356e4e96d419d66d13c2e67b73a50346f.tar.gz
krino-f12f3f1356e4e96d419d66d13c2e67b73a50346f.zip
an earlier directory's applied results stay claimed for later ones
Diffstat (limited to 'cmd/krino/sort_test.go')
-rw-r--r--cmd/krino/sort_test.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/cmd/krino/sort_test.go b/cmd/krino/sort_test.go
index 22e00b4..071a64d 100644
--- a/cmd/krino/sort_test.go
+++ b/cmd/krino/sort_test.go
@@ -333,3 +333,36 @@ func TestWriteStopsKrinoWhenApplyFails(t *testing.T) {
t.Errorf("d2 was planned after [w]:\n%s", out)
}
}
+
+// TestLaterDirectoryNeverOverwritesAnEarlierOnesResult: what an earlier
+// directory of the run put somewhere stays claimed, so a later directory's
+// (on-conflict overwrite) takes a free name instead of trashing it - as a
+// dry run of the same two directories shows (plan 11 review M1).
+func TestLaterDirectoryNeverOverwritesAnEarlierOnesResult(t *testing.T) {
+ h := home(t)
+ old := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)
+ if code, _, errOut := runCLI(t, "init"); code != 0 {
+ t.Fatal(errOut)
+ }
+ for _, n := range []string{"a", "b"} {
+ p := filepath.Join(h, n, "x.pdf")
+ os.MkdirAll(filepath.Dir(p), 0o755)
+ os.WriteFile(p, []byte("from "+n), 0o644)
+ os.Chtimes(p, old, old)
+ if code, _, errOut := runCLI(t, "new", n, filepath.Join(h, n)); code != 0 {
+ t.Fatal(errOut)
+ }
+ os.WriteFile(filepath.Join(h, ".config", "krino", "dirs", n+".conf"), []byte("(path \"~/"+n+"\")\n(on-conflict overwrite)\n(rule \"out\" (move \"~/Out\"))\n"), 0o644)
+ }
+ if code, out, errOut := runCLI(t, "-y", "a", "b"); code != 0 {
+ t.Fatalf("exit %d\n%s\n%s", code, out, errOut)
+ }
+ for rel, want := range map[string]string{"Out/x.pdf": "from a", "Out/x_1.pdf": "from b"} {
+ if b, err := os.ReadFile(filepath.Join(h, rel)); err != nil || string(b) != want {
+ t.Errorf("%s: %q, %v; want %q", rel, b, err, want)
+ }
+ }
+ if entries, _ := os.ReadDir(filepath.Join(h, ".local", "share", "Trash", "files")); len(entries) != 0 {
+ t.Errorf("the Trash holds %d entries; nothing should have been displaced", len(entries))
+ }
+}