Asynchronous delete (#238)

* Asynchronous deletion, similar to moving

* Reversed some sloppy new lines from previous commit

* Move delete operations to delete.go

* Simplify to use RemoveAll before

* Send errors directly to ui.exprChan directly
This commit is contained in:
Juris Arturs Majors 2019-12-02 12:27:58 +01:00 committed by gokcehan
parent 8327505398
commit f76bf30f65
3 changed files with 24 additions and 5 deletions

5
app.go
View File

@ -179,6 +179,11 @@ func (app *app) loop() {
continue continue
} }
if app.nav.deleting {
app.ui.echoerr("quit: delete operation in progress")
continue
}
log.Print("bye!") log.Print("bye!")
if err := app.writeHistory(); err != nil { if err := app.writeHistory(); err != nil {

View File

@ -470,7 +470,7 @@ func insert(app *app, arg string) {
normal(app) normal(app)
if arg == "y" { 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) app.ui.echoerrf("delete: %s", err)
return return
} }

18
nav.go
View File

@ -248,6 +248,7 @@ type nav struct {
moveCount int moveCount int
moveTotal int moveTotal int
moveUpdate int moveUpdate int
deleting bool
copyBytesChan chan int64 copyBytesChan chan int64
copyTotalChan chan int64 copyTotalChan chan int64
moveCountChan chan int moveCountChan chan int
@ -775,17 +776,30 @@ func (nav *nav) paste(ui *ui) error {
return nil return nil
} }
func (nav *nav) del() error { func (nav *nav) del(ui *ui) error {
list, err := nav.currFileOrSelections() list, err := nav.currFileOrSelections()
if err != nil { if err != nil {
return err return err
} }
go func() {
echo := &callExpr{"echoerr", []string{""}, 1}
errCount := 0
nav.deleting = true
for _, path := range list { for _, path := range list {
if err := os.RemoveAll(path); err != nil { if err := os.RemoveAll(path); err != nil {
return err 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 return nil
} }