security: remediate review B findings
This commit is contained in:
@@ -150,7 +150,49 @@ func (s Local) Trash(path string) error {
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
return wastebasket.Trash(p)
|
||||
if err := wastebasket.Trash(p); err != nil {
|
||||
return err
|
||||
}
|
||||
_ = cleanupSystemTrash(30 * 24 * time.Hour)
|
||||
return nil
|
||||
}
|
||||
|
||||
func cleanupSystemTrash(maxAge time.Duration) error {
|
||||
base := os.Getenv("XDG_DATA_HOME")
|
||||
if base == "" {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
base = filepath.Join(home, ".local", "share")
|
||||
}
|
||||
root := filepath.Join(base, "Trash")
|
||||
filesDir := filepath.Join(root, "files")
|
||||
infoDir := filepath.Join(root, "info")
|
||||
now := time.Now()
|
||||
entries, err := os.ReadDir(infoDir)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
for _, entry := range entries {
|
||||
if entry.IsDir() || filepath.Ext(entry.Name()) != ".trashinfo" {
|
||||
continue
|
||||
}
|
||||
info, err := entry.Info()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if now.Sub(info.ModTime()) <= maxAge {
|
||||
continue
|
||||
}
|
||||
name := strings.TrimSuffix(entry.Name(), ".trashinfo")
|
||||
_ = os.Remove(filepath.Join(infoDir, entry.Name()))
|
||||
_ = os.RemoveAll(filepath.Join(filesDir, name))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s Local) MoveToTrash(path, trashRoot string) error {
|
||||
|
||||
Reference in New Issue
Block a user