aboutsummaryrefslogtreecommitdiff
path: root/internal/journal/read.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/journal/read.go')
-rw-r--r--internal/journal/read.go38
1 files changed, 33 insertions, 5 deletions
diff --git a/internal/journal/read.go b/internal/journal/read.go
index 9099c0d..438e6ba 100644
--- a/internal/journal/read.go
+++ b/internal/journal/read.go
@@ -43,7 +43,19 @@ type Run struct {
Dirs []string
Counts map[string]int // action -> count of status "ok"
Undone bool // a later run reversed this one
- UndoOf string // for an undo run, the run it reverses; "" otherwise
+ // PartlyUndone is set with Undone while fewer of the run's reversible
+ // steps have been reversed, over all its undo runs, than it took
+ // (triage 34l): some were declined, refused or failed.
+ PartlyUndone bool
+ UndoOf string // for an undo run, the run it reverses; "" otherwise
+}
+
+// reversible names the undo action of each logged action undo can reverse;
+// delete (permanent) has none, and mkdir's removal is tidiness, not a
+// restoration (ranAnyUndoStep).
+var reversible = map[string]string{
+ "move": "undo-move", "rename": "undo-rename", "copy": "undo-copy",
+ "trash": "undo-trash", "displace": "undo-displace",
}
// ReversedKey identifies one reversal an undo run carried out: the file's
@@ -247,11 +259,19 @@ func Runs(path string, n int) ([]Run, error) {
// run-start line - and therefore its claim on pendingUndo - is always
// written before its own step entries, so whether it actually reversed
// anything cannot be known until its Counts are complete.
- undoes := make(map[string]bool) // run IDs actually reversed by some later run
+ undoes := make(map[string]bool) // run IDs actually reversed by some later run
+ reversed := make(map[string]int) // run ID -> reversals carried out by all its undo runs
for undoRun, orig := range pendingUndo {
- if r, ok := byID[undoRun]; ok && ranAnyUndoStep(r.Counts) {
+ r, ok := byID[undoRun]
+ if !ok {
+ continue
+ }
+ if ranAnyUndoStep(r.Counts) {
undoes[orig] = true
}
+ for _, undo := range reversible {
+ reversed[orig] += r.Counts[undo]
+ }
}
runs := make([]Run, len(order))
@@ -260,8 +280,16 @@ func Runs(path string, n int) ([]Run, error) {
}
sort.SliceStable(runs, func(i, j int) bool { return runs[i].Start.After(runs[j].Start) })
for i := range runs {
- runs[i].Undone = undoes[runs[i].ID]
- runs[i].UndoOf = pendingUndo[runs[i].ID]
+ r := &runs[i]
+ r.Undone = undoes[r.ID]
+ r.UndoOf = pendingUndo[r.ID]
+ if r.Undone {
+ took := 0
+ for action := range reversible {
+ took += r.Counts[action]
+ }
+ r.PartlyUndone = reversed[r.ID] < took
+ }
}
if n > 0 && n < len(runs) {