fix: harden exclusive file creation and webdav writes

This commit is contained in:
OpenClaw Agent
2026-09-22 00:30:39 +08:00
parent 05af077c73
commit f3d80e939e
4 changed files with 116 additions and 163 deletions
+15
View File
@@ -30,6 +30,10 @@ type Storage interface {
List(path string) ([]os.FileInfo, error)
}
type ExclusiveCreator interface {
CreateExclusive(path string) (*os.File, error)
}
type Local struct{ Root string }
func (s Local) real(path string) (string, error) {
@@ -95,6 +99,17 @@ func (s Local) Create(path string) (*os.File, error) {
}
return os.Create(p)
}
func (s Local) CreateExclusive(path string) (*os.File, error) {
p, e := s.real(path)
if e != nil {
return nil, e
}
if e = os.MkdirAll(filepath.Dir(p), 0755); e != nil {
return nil, e
}
return os.OpenFile(p, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0644)
}
func (s Local) Remove(path string) error {
p, e := s.real(path)
if e == nil {