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/plan.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/plan.go')
| -rw-r--r-- | gui/internal/ui/plan.go | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/gui/internal/ui/plan.go b/gui/internal/ui/plan.go index 1ee2a51..e59d4dc 100644 --- a/gui/internal/ui/plan.go +++ b/gui/internal/ui/plan.go @@ -4,6 +4,7 @@ package ui import ( "context" + "errors" "fmt" "os" "path/filepath" @@ -63,6 +64,7 @@ type planView struct { previewOff bool sortFollowsPrefs bool startSelected bool + applying bool menu *gtk.Popover keep *gtk.Button menuRow int @@ -555,6 +557,8 @@ func (p *planView) onApply() { return } n := p.tab.SelectedCount() + p.applying = true + p.w.setApplying(true) p.setBusy(true) p.w.setStatus("applying %d file(s)...", n) var res *engine.ApplyResult @@ -563,6 +567,8 @@ func (p *planView) onApply() { res, err = p.tab.Apply(ctx) return err }, func(err error) { + p.applying = false + p.w.setApplying(false) p.setBusy(false) p.apply.SetSensitive(false) p.fillList() @@ -576,17 +582,27 @@ func (p *planView) onApply() { } // closeTab drops the open plan and releases the directory's lock. -func (p *planView) closeTab() { +func (p *planView) closeTab() bool { if p.tab == nil { - return + return true } if err := p.tab.Close(); err != nil { p.w.setStatus("%s: %v", escape(p.tab.Dir.Name), err) + if errors.Is(err, model.ErrApplying) { + // The lock and the log must stay put until the apply is done, + // or files move with nothing recording them. + return false + } } p.tab = nil p.fillList() + return true } +// busyApplying reports whether an apply is in flight, so the window can +// refuse anything that would take the lock or the log away from it. +func (p *planView) busyApplying() bool { return p.applying } + // setBusy turns the buttons on or off around a background operation. func (p *planView) setBusy(busy bool) { p.scan.SetSensitive(!busy) |
