aboutsummaryrefslogtreecommitdiff
path: root/cmd/krino
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
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')
-rw-r--r--cmd/krino/sort.go20
-rw-r--r--cmd/krino/sort_test.go33
2 files changed, 51 insertions, 2 deletions
diff --git a/cmd/krino/sort.go b/cmd/krino/sort.go
index 5a175a4..b516629 100644
--- a/cmd/krino/sort.go
+++ b/cmd/krino/sort.go
@@ -151,6 +151,7 @@ func cmdSort(g *globals, names []string, stdout, stderr io.Writer) int {
continue
}
+ var applied []string // where this directory's applied steps put files
quit := func() bool {
defer func() {
if rerr := l.Release(); rerr != nil {
@@ -262,6 +263,15 @@ func cmdSort(g *globals, names []string, stdout, stderr io.Writer) int {
notReviewed = len(actionable) - len(reviewedChains(actionable, approved))
}
res, aerr := e.Apply(ctx, toApply, approved, j, run)
+ if res != nil {
+ for _, fr := range res.Files {
+ for _, sr := range fr.Steps {
+ if sr.Status == "ok" && sr.Dst != "" {
+ applied = append(applied, sr.Dst)
+ }
+ }
+ }
+ }
if aerr != nil {
// Interrupted mid-apply (fix round 2026-09-12/item 2):
// treated exactly like the cancelled lock wait above - not
@@ -290,9 +300,15 @@ func cmdSort(g *globals, names []string, stdout, stderr io.Writer) int {
// This directory is applied (or skipped) now, so the disk is the
// truth for the next one: its claims - sources it moved away,
// destinations it planned but declined or failed - must not
- // block a later directory (triage 28i). A dry run applies
- // nothing, so there they carry over.
+ // block a later directory (triage 28i). What it did put
+ // somewhere stays claimed, so a later (on-conflict overwrite)
+ // takes a free name rather than trash this run's own result
+ // (plan 11 review M1). A dry run applies nothing, so there every
+ // claim carries over.
claims = plan.NewClaims()
+ for _, p := range applied {
+ claims.Claim(p)
+ }
}
}
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))
+ }
+}