diff --git a/app.go b/app.go index 09dbeb3..35e718e 100644 --- a/app.go +++ b/app.go @@ -179,6 +179,11 @@ func (app *app) loop() { continue } + if app.nav.deleting { + app.ui.echoerr("quit: delete operation in progress") + continue + } + log.Print("bye!") if err := app.writeHistory(); err != nil { diff --git a/eval.go b/eval.go index 2d0ade2..814a00e 100644 --- a/eval.go +++ b/eval.go @@ -470,7 +470,7 @@ func insert(app *app, arg string) { normal(app) if arg == "y" { - if err := app.nav.del(); err != nil { + if err := app.nav.del(app.ui); err != nil { app.ui.echoerrf("delete: %s", err) return } diff --git a/nav.go b/nav.go index 1921387..e55c6c6 100644 --- a/nav.go +++ b/nav.go @@ -248,6 +248,7 @@ type nav struct { moveCount int moveTotal int moveUpdate int + deleting bool copyBytesChan chan int64 copyTotalChan chan int64 moveCountChan chan int @@ -775,16 +776,29 @@ func (nav *nav) paste(ui *ui) error { return nil } -func (nav *nav) del() error { +func (nav *nav) del(ui *ui) error { list, err := nav.currFileOrSelections() if err != nil { return err } - for _, path := range list { - if err := os.RemoveAll(path); err != nil { - return err + go func() { + echo := &callExpr{"echoerr", []string{""}, 1} + errCount := 0 + nav.deleting = true + + for _, path := range list { + if err := os.RemoveAll(path); err != nil { + errCount++ + echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err) + ui.exprChan <- echo + } } + nav.deleting = false + }() + + if err := remote("send sync"); err != nil { + return fmt.Errorf("delete: %s", err) } return nil