search only "info" folder for trashinfo files
swap filepath.WalkDir for os.ReadDir I don't really know why I used WalkDir in the first place
This commit is contained in:
parent
44da4acbbd
commit
cc973694e5
|
@ -62,42 +62,49 @@ func (t TrashInfo) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func FindTrash(trashdir, ogdir string, fltr *filter.Filter) (Files, error) {
|
func FindTrash(trashdir, ogdir string, fltr *filter.Filter) (Files, error) {
|
||||||
|
log.Debugf("searching for trashinfo files in %s", trashdir)
|
||||||
var files Files
|
var files Files
|
||||||
outerr := filepath.WalkDir(trashdir, func(path string, dirEntry fs.DirEntry, err error) error {
|
|
||||||
|
infodir := filepath.Join(trashdir, "info")
|
||||||
|
dirs, err := os.ReadDir(infodir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("what happened?? what is %s?", err)
|
return Files{}, err
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ignore self, directories, and non trashinfo files
|
for _, dir := range dirs {
|
||||||
if path == trashdir || dirEntry.IsDir() || filepath.Ext(path) != trashInfoExt {
|
if dir.IsDir() || filepath.Ext(dir.Name()) != trashInfoExt {
|
||||||
return nil
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
path := filepath.Join(infodir, dir.Name())
|
||||||
|
|
||||||
// trashinfo is just an ini file, so
|
// trashinfo is just an ini file, so
|
||||||
c, err := ini.Load(path)
|
trashInfo, err := ini.Load(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
log.Errorf("error reading %s: %s", path, err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
if section := c.Section(trashInfoSec); section != nil {
|
|
||||||
|
if section := trashInfo.Section(trashInfoSec); section != nil {
|
||||||
basepath := section.Key(trashInfoPath).String()
|
basepath := section.Key(trashInfoPath).String()
|
||||||
|
|
||||||
filename := filepath.Base(basepath)
|
filename := filepath.Base(basepath)
|
||||||
trashedpath := strings.Replace(strings.Replace(path, "info", "files", 1), trashInfoExt, "", 1)
|
trashedpath := strings.Replace(strings.Replace(path, "info", "files", 1), trashInfoExt, "", 1)
|
||||||
info, err := os.Lstat(trashedpath)
|
info, err := os.Lstat(trashedpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("error reading %s: %s", trashedpath, err)
|
log.Errorf("error reading '%s': %s", trashedpath, err)
|
||||||
return nil
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
s := section.Key(trashInfoDate).Value()
|
s := section.Key(trashInfoDate).Value()
|
||||||
date, err := time.ParseInLocation(trashInfoDateFmt, s, time.Local)
|
date, err := time.ParseInLocation(trashInfoDateFmt, s, time.Local)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
log.Errorf("error parsing date '%s' in trashinfo file '%s': %s", s, path, err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if ogdir != "" && filepath.Dir(basepath) != ogdir {
|
if ogdir != "" && filepath.Dir(basepath) != ogdir {
|
||||||
return nil
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if fltr.Match(info) {
|
if fltr.Match(info) {
|
||||||
|
@ -112,11 +119,8 @@ func FindTrash(trashdir, ogdir string, fltr *filter.Filter) (Files, error) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if outerr != nil {
|
|
||||||
return Files{}, outerr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return files, nil
|
return files, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue