webdav: introduce MoveOptions

This commit is contained in:
Simon Ser
2024-01-18 13:25:14 +01:00
parent 790ebfc5f8
commit b821d8c1ea
4 changed files with 17 additions and 6 deletions

View File

@@ -21,7 +21,7 @@ type FileSystem interface {
RemoveAll(ctx context.Context, name string) error
Mkdir(ctx context.Context, name string) error
Copy(ctx context.Context, name, dest string, options *CopyOptions) (created bool, err error)
Move(ctx context.Context, name, dest string, overwrite bool) (created bool, err error)
Move(ctx context.Context, name, dest string, options *MoveOptions) (created bool, err error)
}
// Handler handles WebDAV HTTP requests. It can be used to create a WebDAV
@@ -243,7 +243,10 @@ func (b *backend) Copy(r *http.Request, dest *internal.Href, recursive, overwrit
}
func (b *backend) Move(r *http.Request, dest *internal.Href, overwrite bool) (created bool, err error) {
created, err = b.FileSystem.Move(r.Context(), r.URL.Path, dest.Path, overwrite)
options := MoveOptions{
NoOverwrite: !overwrite,
}
created, err = b.FileSystem.Move(r.Context(), r.URL.Path, dest.Path, &options)
if os.IsExist(err) {
return false, &internal.HTTPError{http.StatusPreconditionFailed, err}
}