be less scared of broken symlinks

This commit is contained in:
Lilian Jónsdóttir 2024-07-15 22:41:34 -07:00
parent 586c8b34cb
commit 8a4b195a72
2 changed files with 4 additions and 5 deletions

View file

@ -40,7 +40,7 @@ func (f DiskFile) String() string {
} }
func NewDisk(path string) (DiskFile, error) { func NewDisk(path string) (DiskFile, error) {
info, err := os.Stat(path) info, err := os.Lstat(path)
if err != nil { if err != nil {
return DiskFile{}, err return DiskFile{}, err
} }

View file

@ -82,9 +82,8 @@ func FindTrash(trashdir, ogdir string, f *filter.Filter) (files Files, outerr er
filename := filepath.Base(basepath) filename := filepath.Base(basepath)
trashedpath := strings.Replace(strings.Replace(path, "info", "files", 1), trash_info_ext, "", 1) trashedpath := strings.Replace(strings.Replace(path, "info", "files", 1), trash_info_ext, "", 1)
info, err := os.Stat(trashedpath) info, err := os.Lstat(trashedpath)
if err != nil { if err != nil {
// TODO: do something about it
log.Errorf("error reading %s: %s", trashedpath, err) log.Errorf("error reading %s: %s", trashedpath, err)
return nil return nil
} }
@ -130,7 +129,7 @@ func Restore(files Files) (restored int, err error) {
var outpath string = dirs.UnEscape(file.ogpath) var outpath string = dirs.UnEscape(file.ogpath)
var cancel bool var cancel bool
log.Infof("restoring %s back to %s\n", file.name, outpath) log.Infof("restoring %s back to %s\n", file.name, outpath)
if _, e := os.Stat(outpath); e == nil { if _, e := os.Lstat(outpath); e == nil {
outpath, cancel = promptNewPath(outpath) outpath, cancel = promptNewPath(outpath)
} }
@ -167,7 +166,7 @@ func Remove(files Files) (removed int, err error) {
log.Infof("removing %s permanently forever!!!", file.name) log.Infof("removing %s permanently forever!!!", file.name)
if err = os.Remove(file.path); err != nil { if err = os.Remove(file.path); err != nil {
if i, e := os.Stat(file.path); e == nil && i.IsDir() { if i, e := os.Lstat(file.path); e == nil && i.IsDir() {
err = os.RemoveAll(file.path) err = os.RemoveAll(file.path)
if err != nil { if err != nil {
return removed, err return removed, err