fix: align WebDAV MOVE overwrite and source errors
This commit is contained in:
@@ -914,9 +914,11 @@ func (f *webdavStorageFS) Copy(ctx context.Context, name, dest string, opts *web
|
||||
func (f *webdavStorageFS) Move(ctx context.Context, name, dest string, opts *webdav.MoveOptions) (bool, error) {
|
||||
src := davStoragePath(name)
|
||||
dst := davStoragePath(dest)
|
||||
if opts != nil && opts.NoOverwrite {
|
||||
if opts == nil || opts.NoOverwrite {
|
||||
if _, err := f.store.Stat(dst); err == nil {
|
||||
return false, fmt.Errorf("destination exists")
|
||||
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 {
|
||||
@@ -926,7 +928,16 @@ func (f *webdavStorageFS) Move(ctx context.Context, name, dest string, opts *web
|
||||
return false, webdav.NewHTTPError(http.StatusForbidden, fmt.Errorf("cross-root move is not supported"))
|
||||
}
|
||||
}
|
||||
if _, err := f.store.Stat(src); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return false, webdav.NewHTTPError(http.StatusNotFound, err)
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
if err := f.store.Rename(src, dst); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return false, webdav.NewHTTPError(http.StatusNotFound, err)
|
||||
}
|
||||
return false, webdav.NewHTTPError(http.StatusForbidden, err)
|
||||
}
|
||||
return true, nil
|
||||
|
||||
Reference in New Issue
Block a user