diff options
author | Koni Marti <koni.marti@gmail.com> | 2023-11-06 22:25:11 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-11-12 12:53:11 +0100 |
commit | a35d9bab4664bb60163cfce53faa4eb68c1a69f3 (patch) | |
tree | 5979457c2f000182afc0bfe00bbfd42a5f0f60a8 /app/dirlist.go | |
parent | 7bd9239d94a5371eacf001766de9c2d53b7fde43 (diff) | |
download | aerc-a35d9bab4664bb60163cfce53faa4eb68c1a69f3.tar.gz |
rmdir: ensure proper sequence of operations
Ensure the proper sequence of opening and removing a directory. Fix a
potential race between the OpenDirectory (issued by dirlist.Select())
and the RemoveDirectory messages when removing a directory.
Due to the delay in the current dirlist.Select() function, the
RemoveDirectory message can arrive at the backend before the directory
was changed to a different one. This can cause an error on some imap
servers and problems with the watcher on the maildir backends.
Introduce dirlist.Open() that accepts a callback function so that the
operations can be performed in proper sequence. Dirlist.Select() is now
a wrapper call to dirlist.Open().
Reported-by: inwit <inwit@sindominio.net>
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Tested-by: Inwit <inwit@sindominio.net>
Diffstat (limited to 'app/dirlist.go')
-rw-r--r-- | app/dirlist.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/app/dirlist.go b/app/dirlist.go index d77ace42..708eb824 100644 --- a/app/dirlist.go +++ b/app/dirlist.go @@ -26,6 +26,7 @@ type DirectoryLister interface { Selected() string Select(string) + Open(string, time.Duration, func(types.WorkerMessage)) Update(types.WorkerMessage) List() []string @@ -172,11 +173,16 @@ func (dirlist *DirectoryList) ExpandFolder() { } func (dirlist *DirectoryList) Select(name string) { + dirlist.Open(name, dirlist.UiConfig(name).DirListDelay, nil) +} + +func (dirlist *DirectoryList) Open(name string, delay time.Duration, + cb func(types.WorkerMessage), +) { dirlist.selecting = name dirlist.cancel() dirlist.ctx, dirlist.cancel = context.WithCancel(context.Background()) - delay := dirlist.UiConfig(name).DirListDelay go func(ctx context.Context) { defer log.PanicHandler() @@ -198,6 +204,9 @@ func (dirlist *DirectoryList) Select(name string) { case *types.Cancelled: log.Debugf("OpenDirectory cancelled") } + if cb != nil { + cb(msg) + } }) case <-ctx.Done(): log.Tracef("dirlist: skip %s", name) |