fix: preserve WebDAV MOVE destination precedence
This commit is contained in:
@@ -1437,10 +1437,19 @@ func (f *webdavAuthFS) Move(ctx context.Context, name, dest string, opts *webdav
|
||||
// This matters because MOVE to an occupied destination returns 412 even
|
||||
// when the source has disappeared, while a missing source with a free
|
||||
// destination is reported as 403.
|
||||
if opts == nil || !opts.NoOverwrite {
|
||||
if err := f.authorizeOverwrite(ctx, dest); err != nil {
|
||||
return false, err
|
||||
destExists := false
|
||||
if _, err := f.inner.Stat(ctx, dest); err == nil {
|
||||
destExists = true
|
||||
} else if !isWebDAVNotFound(err) {
|
||||
return false, err
|
||||
}
|
||||
if destExists {
|
||||
if opts == nil || !opts.NoOverwrite {
|
||||
if err := f.authorizeOverwrite(ctx, dest); err != nil {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
return false, webdav.NewHTTPError(http.StatusPreconditionFailed, fmt.Errorf("destination exists"))
|
||||
}
|
||||
if _, err := f.inner.Stat(ctx, name); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
@@ -1454,6 +1463,13 @@ func (f *webdavAuthFS) Move(ctx context.Context, name, dest string, opts *webdav
|
||||
return f.inner.Move(ctx, name, dest, opts)
|
||||
}
|
||||
|
||||
func isWebDAVNotFound(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
return os.IsNotExist(err) || strings.HasPrefix(err.Error(), "404 Not Found:")
|
||||
}
|
||||
|
||||
func (f *webdavAuthFS) authorizeOverwrite(ctx context.Context, dest string) error {
|
||||
info, err := f.inner.Stat(ctx, dest)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user