diff options
Diffstat (limited to 'internal/journal/read_test.go')
| -rw-r--r-- | internal/journal/read_test.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/internal/journal/read_test.go b/internal/journal/read_test.go index d2bbd3a..dd202a4 100644 --- a/internal/journal/read_test.go +++ b/internal/journal/read_test.go @@ -808,3 +808,52 @@ func TestRunsIgnoresAPermanentlyDeletedFilesSteps(t *testing.T) { } } } + +// TestPermanentDeleteDoesNotExcuseItsDisplace: a chain that overwrote and +// then permanently deleted trashed a file the user owned. That file can +// come back, so until it does the run is only partly undone - subtracting +// every reversible step of a permanently deleted file, its displace +// included, made krino report the run fully undone while the user's file +// was still in the Trash. +func TestPermanentDeleteDoesNotExcuseItsDisplace(t *testing.T) { + path := filepath.Join(t.TempDir(), "krino.log") + w, _ := Open(path) + now := time.Now() + w.Append(Entry{Time: now, Run: "A", Action: "run-start", Status: "ok"}) + w.Append(Entry{Time: now, Run: "A", Dir: "dl", File: "a.pdf", Step: 1, + Action: "displace", Status: "ok", Src: "/archive/a.pdf", Dst: "/trash/a.pdf", Detail: "a.pdf"}) + w.Append(Entry{Time: now, Run: "A", Dir: "dl", File: "a.pdf", Step: 1, + Action: "move", Status: "ok", Src: "/dl/a.pdf", Dst: "/archive/a.pdf"}) + w.Append(Entry{Time: now, Run: "A", Dir: "dl", File: "a.pdf", Step: 2, + Action: "delete", Status: "ok", Src: "/archive/a.pdf"}) + // A second file the same run moved, which undo does put back. + w.Append(Entry{Time: now, Run: "A", Dir: "dl", File: "b.txt", Step: 1, + Action: "move", Status: "ok", Src: "/dl/b.txt", Dst: "/dl/Text/b.txt"}) + w.Append(Entry{Time: now, Run: "A", Action: "run-end", Status: "ok"}) + w.Append(Entry{Time: now.Add(time.Hour), Run: "B", Action: "run-start", Status: "ok", + Detail: undoOfPrefix + "A"}) + w.Append(Entry{Time: now.Add(time.Hour), Run: "B", Dir: "dl", File: "b.txt", Step: 1, + Action: "undo-move", Status: "ok", Src: "/dl/Text/b.txt", Dst: "/dl/b.txt"}) + w.Append(Entry{Time: now.Add(time.Hour), Run: "B", Action: "run-end", Status: "ok"}) + w.Close() + + runs, err := Runs(path, 0) + if err != nil { + t.Fatal(err) + } + var orig *Run + for i := range runs { + if runs[i].ID == "A" { + orig = &runs[i] + } + } + if orig == nil { + t.Fatal("the original run is not in the log") + } + if !orig.Undone { + t.Fatal("the run is not marked undone at all") + } + if !orig.PartlyUndone { + t.Error("a run whose displaced file is still in the Trash reads as fully undone") + } +} |
