feat: implement configurable delete modes

This commit is contained in:
OpenClaw Agent
2026-09-21 13:38:18 +08:00
parent 633c833d1c
commit add2a22416
7 changed files with 102 additions and 5 deletions
+25
View File
@@ -91,6 +91,31 @@ func (m Multi) Remove(p string) error {
}
return r.Remove(rel)
}
func (m Multi) Trash(p string) error {
r, rel, ok := m.find(p)
if !ok {
return os.ErrNotExist
}
return r.Trash(rel)
}
func (m Multi) MoveToTrash(p, trashRoot string) error {
r, rel, ok := m.find(p)
if !ok {
return os.ErrNotExist
}
return r.MoveToTrash(rel, filepath.Join(trashRoot, m.RootName(r)))
}
func (m Multi) RootName(r Local) string {
for i := range m.Roots {
if m.Roots[i].Root == r.Root {
return m.Names[i]
}
}
return "root"
}
func (m Multi) Rename(a, b string) error {
ra, aa, oka := m.find(a)
rb, bb, okb := m.find(b)
+35
View File
@@ -2,12 +2,20 @@ package storage
import (
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
"strings"
"github.com/Bios-Marcel/wastebasket"
)
type Trashable interface {
Trash(path string) error
MoveToTrash(path, trashRoot string) error
}
type Storage interface {
Stat(path string) (os.FileInfo, error)
Open(path string) (*os.File, error)
@@ -67,6 +75,33 @@ func (s Local) Remove(path string) error {
}
return os.RemoveAll(p)
}
func (s Local) Trash(path string) error {
p, e := s.real(path)
if e != nil {
return e
}
return wastebasket.Trash(p)
}
func (s Local) MoveToTrash(path, trashRoot string) error {
p, e := s.real(path)
if e != nil {
return e
}
if e = os.MkdirAll(trashRoot, 0755); e != nil {
return e
}
name := filepath.Base(p)
target := filepath.Join(trashRoot, name)
for i := 1; ; i++ {
if _, e = os.Lstat(target); os.IsNotExist(e) {
break
}
target = filepath.Join(trashRoot, fmt.Sprintf("%s.%d", name, i))
}
return os.Rename(p, target)
}
func (s Local) Rename(a, b string) error {
pa, e := s.real(a)
if e != nil {