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:
parent
8327505398
commit
f76bf30f65
5
app.go
5
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 {
|
||||
|
2
eval.go
2
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
|
||||
}
|
||||
|
18
nav.go
18
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,17 +776,30 @@ 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
|
||||
}
|
||||
|
||||
go func() {
|
||||
echo := &callExpr{"echoerr", []string{""}, 1}
|
||||
errCount := 0
|
||||
nav.deleting = true
|
||||
|
||||
for _, path := range list {
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user