Skip to content

Commit

Permalink
rmdir: back to current folder upon error
Browse files Browse the repository at this point in the history
Jump back to the current folder consistently when encountering an error.
This has only been partly implemented. For example, when you try to
remove a notmuch folder, the remove operation will fail because it is
unsupported. However, you would end up in a different directory because
a directoy change is done before trying to remove the current folder. If
this happens make sure you end up in the current directory again.

Fixes: a35d9ba ("rmdir: ensure proper sequence of operations")
Signed-off-by: Koni Marti <[email protected]>
Acked-by: Robin Jarry <[email protected]>
  • Loading branch information
konimarti authored and rjarry committed Nov 22, 2023
1 parent 30d28d0 commit 019a1a5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion commands/account/rmdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ func (r RemoveDir) Execute(args []string) error {
return errors.New("No directory to move to afterwards!")
}

reopenCurrentDir := func() { acct.Directories().Open(curDir, 0, nil) }

acct.Directories().Open(newDir, 0, func(msg types.WorkerMessage) {
switch msg.(type) {
case *types.Done:
break
case *types.Error:
app.PushError("Could not change directory")
acct.Directories().Open(curDir, 0, nil)
reopenCurrentDir()
return
default:
return
Expand All @@ -101,8 +103,10 @@ func (r RemoveDir) Execute(args []string) error {
app.PushStatus("Directory removed.", 10*time.Second)
case *types.Error:
app.PushError(msg.Error.Error())
reopenCurrentDir()
case *types.Unsupported:
app.PushError(":rmdir is not supported by the backend.")
reopenCurrentDir()
}
})
})
Expand Down

0 comments on commit 019a1a5

Please sign in to comment.