webdav: move WebDAV semantics handling to LocalFileSystem

This commit is contained in:
Simon Ser 2020-01-21 21:49:54 +01:00
parent 04bcea1ee8
commit a2ad695145
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 9 additions and 7 deletions

View File

@ -66,6 +66,13 @@ func (fs LocalFileSystem) RemoveAll(name string) error {
if err != nil { if err != nil {
return err return err
} }
// WebDAV semantics are that it should return a "404 Not Found" error in
// case the resource doesn't exist. We need to Stat before RemoveAll.
if _, err = os.Stat(p); err != nil {
return err
}
return os.RemoveAll(p) return os.RemoveAll(p)
} }

View File

@ -186,14 +186,9 @@ func (b *backend) Put(r *http.Request) error {
} }
func (b *backend) Delete(r *http.Request) error { func (b *backend) Delete(r *http.Request) error {
// WebDAV semantics are that it should return a "404 Not Found" error in err := b.FileSystem.RemoveAll(r.URL.Path)
// case the resource doesn't exist. We need to Stat before RemoveAll.
_, err := b.FileSystem.Stat(r.URL.Path)
if os.IsNotExist(err) { if os.IsNotExist(err) {
return &internal.HTTPError{Code: http.StatusNotFound, Err: err} return &internal.HTTPError{Code: http.StatusNotFound, Err: err}
} else if err != nil {
return err
} }
return err
return b.FileSystem.RemoveAll(r.URL.Path)
} }