From a2ad695145d7b6c1d5a537eed52b9865080cdd19 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 21 Jan 2020 21:49:54 +0100 Subject: [PATCH] webdav: move WebDAV semantics handling to LocalFileSystem --- fs_local.go | 7 +++++++ server.go | 9 ++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/fs_local.go b/fs_local.go index a3809f8..46b3983 100644 --- a/fs_local.go +++ b/fs_local.go @@ -66,6 +66,13 @@ func (fs LocalFileSystem) RemoveAll(name string) error { if err != nil { 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) } diff --git a/server.go b/server.go index d6fc4c9..1b4d80d 100644 --- a/server.go +++ b/server.go @@ -186,14 +186,9 @@ func (b *backend) Put(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 - // case the resource doesn't exist. We need to Stat before RemoveAll. - _, err := b.FileSystem.Stat(r.URL.Path) + err := b.FileSystem.RemoveAll(r.URL.Path) if os.IsNotExist(err) { return &internal.HTTPError{Code: http.StatusNotFound, Err: err} - } else if err != nil { - return err } - - return b.FileSystem.RemoveAll(r.URL.Path) + return err }