From 34eef6a228c87c9963c685a7b50684fa8244cb8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lilian=20J=C3=B3nsd=C3=B3ttir?= Date: Tue, 13 Aug 2024 14:51:55 -0700 Subject: [PATCH] replace os.Stat with os.Lstat --- internal/files/trash.go | 8 ++++---- internal/prompt/prompt.go | 2 +- main.go | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/files/trash.go b/internal/files/trash.go index 106822e..95f6373 100644 --- a/internal/files/trash.go +++ b/internal/files/trash.go @@ -257,7 +257,7 @@ func restore(files Files) (restored int, err error) { } basedir := filepath.Dir(outpath) - if _, e := os.Stat(basedir); e != nil { + if _, e := os.Lstat(basedir); e != nil { if err = os.MkdirAll(basedir, executePerm); err != nil { return restored, err } @@ -321,7 +321,7 @@ func getTrashFilenames(filename, trashDir string) (string, string) { ) info := filepath.Join(infodir, filename+trashInfoExt) - if _, err := os.Stat(info); os.IsNotExist(err) { + if _, err := os.Lstat(info); os.IsNotExist(err) { // doesn't exist, so use it path := filepath.Join(filedir, filename) return dirs.PercentEncode(info), dirs.PercentEncode(path) @@ -335,8 +335,8 @@ func getTrashFilenames(filename, trashDir string) (string, string) { rando := randomString(randomStrLength) newInfo := filepath.Join(infodir, filename+rando+trashInfoExt) newFile := filepath.Join(filedir, filename+rando) - _, infoErr := os.Stat(newInfo) - _, fileErr := os.Stat(newFile) + _, infoErr := os.Lstat(newInfo) + _, fileErr := os.Lstat(newFile) if os.IsNotExist(infoErr) && os.IsNotExist(fileErr) { path := filepath.Join(filedir, filename+rando) log.Debugf("settled on random name %s%s on the %s try", filename, rando, humanize.Ordinal(tries)) diff --git a/internal/prompt/prompt.go b/internal/prompt/prompt.go index f57e511..9e115e8 100644 --- a/internal/prompt/prompt.go +++ b/internal/prompt/prompt.go @@ -52,7 +52,7 @@ func NewPath(path string) (string, bool) { Run(); err != nil { return path, false } - if _, e := os.Stat(path); e != nil { + if _, e := os.Lstat(path); e != nil { return path, false } default: diff --git a/main.go b/main.go index 786a53c..e3201d5 100644 --- a/main.go +++ b/main.go @@ -62,12 +62,12 @@ var ( // ensure personal trash directories exist homeTrash := filepath.Join(xdg.DataHome, "Trash") - if _, e := os.Stat(filepath.Join(homeTrash, "info")); os.IsNotExist(e) { + if _, e := os.Lstat(filepath.Join(homeTrash, "info")); os.IsNotExist(e) { if err := os.MkdirAll(filepath.Join(homeTrash, "info"), executePerm); err != nil { return err } } - if _, e := os.Stat(filepath.Join(homeTrash, "files")); os.IsNotExist(e) { + if _, e := os.Lstat(filepath.Join(homeTrash, "files")); os.IsNotExist(e) { if err := os.MkdirAll(filepath.Join(homeTrash, "files"), executePerm); err != nil { return err }