fix: harden exclusive file creation and webdav writes
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user