fix: align WebDAV overwrite and missing-resource errors
This commit is contained in:
@@ -825,6 +825,12 @@ func (f *webdavStorageFS) RemoveAll(ctx context.Context, name string, opts *webd
|
||||
if p == "" {
|
||||
return fmt.Errorf("cannot remove storage root")
|
||||
}
|
||||
if _, err := f.store.Stat(p); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return webdav.NewHTTPError(http.StatusNotFound, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
if f.removeMode == 1 {
|
||||
if t, ok := f.store.(storage.Trashable); ok {
|
||||
return t.Trash(p)
|
||||
@@ -847,12 +853,24 @@ func (f *webdavStorageFS) Mkdir(ctx context.Context, name string) error {
|
||||
if p == "" {
|
||||
return fmt.Errorf("cannot create storage root")
|
||||
}
|
||||
if _, err := f.store.Stat(p); err == nil {
|
||||
return webdav.NewHTTPError(http.StatusMethodNotAllowed, fmt.Errorf("resource already exists"))
|
||||
} else if !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
return f.store.MkdirAll(p)
|
||||
}
|
||||
|
||||
func (f *webdavStorageFS) Copy(ctx context.Context, name, dest string, opts *webdav.CopyOptions) (bool, error) {
|
||||
src := davStoragePath(name)
|
||||
dst := davStoragePath(dest)
|
||||
if opts != nil && opts.NoOverwrite {
|
||||
if _, err := f.store.Stat(dst); err == nil {
|
||||
return false, webdav.NewHTTPError(http.StatusPreconditionFailed, fmt.Errorf("destination exists"))
|
||||
} else if !os.IsNotExist(err) {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
if m, ok := f.store.(storage.Multi); ok {
|
||||
srcRoot, _, srcOK := m.FindRoot(src)
|
||||
dstRoot, _, dstOK := m.FindRoot(dst)
|
||||
|
||||
Reference in New Issue
Block a user