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
}
if app.nav.deleting {
app.ui.echoerr("quit: delete operation in progress")
continue
}
log.Print("bye!")
if err := app.writeHistory(); err != nil {

View File

@ -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
}

22
nav.go
View File

@ -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