don't die on error trashing one file

try trashing all the rest instead
This commit is contained in:
Lilian Jónsdóttir 2024-07-30 13:48:52 -07:00
parent c33afe615c
commit 437101b947
2 changed files with 9 additions and 9 deletions

View file

@ -236,14 +236,15 @@ func TrashFile(trashDir, name string) error {
return nil
}
func TrashFiles(trashDir string, files ...string) (trashed int, err error) {
func TrashFiles(trashDir string, files ...string) (trashed int) {
for _, file := range files {
if err = TrashFile(trashDir, file); err != nil {
return trashed, err
if err := TrashFile(trashDir, file); err != nil {
log.Errorf("error trashing file %s: %s", file, err)
continue
}
trashed++
}
return trashed, err
return trashed
}
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())
}
trashed, err := TrashFiles(trashDir, tfs...)
if err != nil {
return err
}
trashed := TrashFiles(trashDir, tfs...)
var files string
if trashed == 1 {
files = "file"

View file

@ -164,7 +164,8 @@ var (
for _, arg := range ctx.Args().Slice() {
file, e := files.NewDisk(arg)
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)
}