From 746bff694cd77dc0f8b2d6d5cbf95e050d66f7d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lilian=20J=C3=B3nsd=C3=B3ttir?= Date: Mon, 15 Jul 2024 15:59:40 -0700 Subject: [PATCH] restore creates directories if necessary --- internal/files/trash.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/internal/files/trash.go b/internal/files/trash.go index 6df706a..5dc83d1 100644 --- a/internal/files/trash.go +++ b/internal/files/trash.go @@ -132,15 +132,26 @@ func Restore(files Files) (restored int, err error) { if _, e := os.Stat(outpath); e == nil { outpath, cancel = promptNewPath(outpath) } + if cancel { continue } + + basedir := filepath.Dir(outpath) + if _, e := os.Stat(basedir); e != nil { + if err = os.MkdirAll(basedir, fs.FileMode(0755)); err != nil { + return restored, err + } + } + if err = os.Rename(file.path, outpath); err != nil { return restored, err } + if err = os.Remove(file.trashinfo); err != nil { return restored, err } + restored++ } return restored, err