replace os.Stat with os.Lstat

This commit is contained in:
Lilian Jónsdóttir 2024-08-13 14:51:55 -07:00
parent 50f4dbda8a
commit 34eef6a228
3 changed files with 7 additions and 7 deletions

View file

@ -257,7 +257,7 @@ func restore(files Files) (restored int, err error) {
} }
basedir := filepath.Dir(outpath) 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 { if err = os.MkdirAll(basedir, executePerm); err != nil {
return restored, err return restored, err
} }
@ -321,7 +321,7 @@ func getTrashFilenames(filename, trashDir string) (string, string) {
) )
info := filepath.Join(infodir, filename+trashInfoExt) 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 // doesn't exist, so use it
path := filepath.Join(filedir, filename) path := filepath.Join(filedir, filename)
return dirs.PercentEncode(info), dirs.PercentEncode(path) return dirs.PercentEncode(info), dirs.PercentEncode(path)
@ -335,8 +335,8 @@ func getTrashFilenames(filename, trashDir string) (string, string) {
rando := randomString(randomStrLength) rando := randomString(randomStrLength)
newInfo := filepath.Join(infodir, filename+rando+trashInfoExt) newInfo := filepath.Join(infodir, filename+rando+trashInfoExt)
newFile := filepath.Join(filedir, filename+rando) newFile := filepath.Join(filedir, filename+rando)
_, infoErr := os.Stat(newInfo) _, infoErr := os.Lstat(newInfo)
_, fileErr := os.Stat(newFile) _, fileErr := os.Lstat(newFile)
if os.IsNotExist(infoErr) && os.IsNotExist(fileErr) { if os.IsNotExist(infoErr) && os.IsNotExist(fileErr) {
path := filepath.Join(filedir, filename+rando) path := filepath.Join(filedir, filename+rando)
log.Debugf("settled on random name %s%s on the %s try", filename, rando, humanize.Ordinal(tries)) log.Debugf("settled on random name %s%s on the %s try", filename, rando, humanize.Ordinal(tries))

View file

@ -52,7 +52,7 @@ func NewPath(path string) (string, bool) {
Run(); err != nil { Run(); err != nil {
return path, false return path, false
} }
if _, e := os.Stat(path); e != nil { if _, e := os.Lstat(path); e != nil {
return path, false return path, false
} }
default: default:

View file

@ -62,12 +62,12 @@ var (
// ensure personal trash directories exist // ensure personal trash directories exist
homeTrash := filepath.Join(xdg.DataHome, "Trash") 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 { if err := os.MkdirAll(filepath.Join(homeTrash, "info"), executePerm); err != nil {
return err 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 { if err := os.MkdirAll(filepath.Join(homeTrash, "files"), executePerm); err != nil {
return err return err
} }