feat: add permission-aware file copy and move

This commit is contained in:
OpenClaw Agent
2026-09-22 02:21:07 +08:00
parent b60d4dc3cb
commit 0ddb04b551
3 changed files with 107 additions and 0 deletions
+18
View File
@@ -26,6 +26,7 @@ type Storage interface {
Create(path string) (*os.File, error)
Remove(path string) error
Rename(oldPath, newPath string) error
Copy(oldPath, newPath string) error
MkdirAll(path string) error
List(path string) ([]os.FileInfo, error)
}
@@ -275,6 +276,23 @@ func copyPath(src, dst string) error {
return os.Chtimes(dst, info.ModTime(), info.ModTime())
}
func (s Local) Copy(a, b string) error {
pa, e := s.real(a)
if e != nil {
return e
}
pb, e := s.real(b)
if e != nil {
return e
}
if _, e := os.Lstat(pb); e == nil {
return os.ErrExist
} else if !os.IsNotExist(e) {
return e
}
return copyPath(pa, pb)
}
func (s Local) Rename(a, b string) error {
pa, e := s.real(a)
if e != nil {