From 437101b94786d988f3a90073206f394b73e20dfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lilian=20J=C3=B3nsd=C3=B3ttir?= Date: Tue, 30 Jul 2024 13:48:52 -0700 Subject: [PATCH] don't die on error trashing one file try trashing all the rest instead --- internal/files/trash.go | 15 +++++++-------- main.go | 3 ++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/files/trash.go b/internal/files/trash.go index 1cea4e5..31078f2 100644 --- a/internal/files/trash.go +++ b/internal/files/trash.go @@ -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" diff --git a/main.go b/main.go index 25412f4..6f85964 100644 --- a/main.go +++ b/main.go @@ -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) }