diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-17 14:11:52 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-17 14:11:52 +0200 |
| commit | ed86f44a926fd1f0d438cbe5e2e10ad5b063db55 (patch) | |
| tree | a0a4c53a9ed5f207b303623e4dfd3cac16ed302a /gui/internal/ui/history.go | |
| parent | 4c6fadfab5434317357ad0272ace7927d2945942 (diff) | |
| download | krino-ed86f44a926fd1f0d438cbe5e2e10ad5b063db55.tar.gz krino-ed86f44a926fd1f0d438cbe5e2e10ad5b063db55.zip | |
the window cannot pull the lock out from under a running apply
Close releases the directory lock and closes the log. The window could
reach it while an apply was still running - saving rules, saving
settings, adding a directory, or closing the window - and the engine
then went on moving files with the log shut underneath: a file moved
that no krino undo can see, the rest of the plan silently abandoned,
and the directory unlocked while krino was still working in it.
PlanTab and UndoTab refuse to close while their apply is in flight
(model.ErrApplying), the window's close request and reloadEngine honour
the refusal instead of ignoring it, and the tabs and Settings are greyed
out for the duration so a button that cannot work says so by being
unavailable rather than by an error afterwards.
The test starts an apply, calls Close from another goroutine while it
is in flight, and requires the refusal.
Diffstat (limited to 'gui/internal/ui/history.go')
| -rw-r--r-- | gui/internal/ui/history.go | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/gui/internal/ui/history.go b/gui/internal/ui/history.go index f82f6e3..3a3166e 100644 --- a/gui/internal/ui/history.go +++ b/gui/internal/ui/history.go @@ -4,6 +4,7 @@ package ui import ( "context" + "errors" "fmt" "strings" @@ -36,6 +37,10 @@ type historyView struct { undo *gtk.Button cancel *gtk.Button + // applying is set while a reversal is in flight; the window refuses + // anything that would take its lock or its log away. + applying bool + tab *model.UndoTab cancelOp context.CancelFunc } @@ -349,6 +354,8 @@ func (h *historyView) onUndo() { return } n := h.tab.SelectedCount() + h.applying = true + h.w.setApplying(true) h.setBusy(true) h.w.setStatus("reversing %d file(s)...", n) var res *engine.ApplyResult @@ -357,6 +364,8 @@ func (h *historyView) onUndo() { res, err = h.tab.Apply(ctx) return err }, func(err error) { + h.applying = false + h.w.setApplying(false) h.setBusy(false) h.fillPlan() h.undo.SetSensitive(false) @@ -404,6 +413,9 @@ func (h *historyView) updateUndoButton() { } // setBusy turns the buttons on or off around a background operation. +// busyApplying reports whether an undo is in flight. +func (h *historyView) busyApplying() bool { return h.applying } + func (h *historyView) setBusy(busy bool) { h.reload.SetSensitive(!busy) h.more.SetSensitive(!busy && len(h.runRows) >= h.limit) @@ -419,15 +431,19 @@ func (h *historyView) setBusy(busy bool) { } // closeTab drops the open undo plan and releases its locks. -func (h *historyView) closeTab() { +func (h *historyView) closeTab() bool { if h.tab == nil { - return + return true } if err := h.tab.Close(); err != nil { h.w.setStatus("undo: %v", err) + if errors.Is(err, model.ErrApplying) { + return false + } } h.tab = nil h.clearPlan() + return true } // clearList removes every row of a ListBox. |
