don't die on error trashing one file
try trashing all the rest instead
This commit is contained in:
parent
c33afe615c
commit
437101b947
|
@ -236,14 +236,15 @@ func TrashFile(trashDir, name string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TrashFiles(trashDir string, files ...string) (trashed int, err error) {
|
func TrashFiles(trashDir string, files ...string) (trashed int) {
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
if err = TrashFile(trashDir, file); err != nil {
|
if err := TrashFile(trashDir, file); err != nil {
|
||||||
return trashed, err
|
log.Errorf("error trashing file %s: %s", file, err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
trashed++
|
trashed++
|
||||||
}
|
}
|
||||||
return trashed, err
|
return trashed
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConfirmTrash(confirm bool, fs Files, trashDir string) error {
|
func ConfirmTrash(confirm bool, fs Files, trashDir string) error {
|
||||||
|
@ -254,10 +255,8 @@ func ConfirmTrash(confirm bool, fs Files, trashDir string) error {
|
||||||
tfs = append(tfs, file.Path())
|
tfs = append(tfs, file.Path())
|
||||||
}
|
}
|
||||||
|
|
||||||
trashed, err := TrashFiles(trashDir, tfs...)
|
trashed := TrashFiles(trashDir, tfs...)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var files string
|
var files string
|
||||||
if trashed == 1 {
|
if trashed == 1 {
|
||||||
files = "file"
|
files = "file"
|
||||||
|
|
3
main.go
3
main.go
|
@ -164,7 +164,8 @@ var (
|
||||||
for _, arg := range ctx.Args().Slice() {
|
for _, arg := range ctx.Args().Slice() {
|
||||||
file, e := files.NewDisk(arg)
|
file, e := files.NewDisk(arg)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
log.Fatalf("cannot trash '%s': No such file or directory", arg)
|
log.Errorf("cannot trash '%s': No such file or directory", arg)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
filesToTrash = append(filesToTrash, file)
|
filesToTrash = append(filesToTrash, file)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue