(w http.ResponseWriter, r *http.Request)
| 291 | } |
| 292 | |
| 293 | func (h *Handler) handleDelete(w http.ResponseWriter, r *http.Request) (status int, err error) { |
| 294 | reqPath, status, err := h.stripPrefix(r.URL.Path) |
| 295 | if err != nil { |
| 296 | return status, err |
| 297 | } |
| 298 | release, status, err := h.confirmLocks(r, reqPath, "") |
| 299 | if err != nil { |
| 300 | return status, err |
| 301 | } |
| 302 | defer release() |
| 303 | |
| 304 | ctx := r.Context() |
| 305 | user := ctx.Value(conf.UserKey).(*model.User) |
| 306 | if !user.CanRemove() { |
| 307 | return http.StatusForbidden, nil |
| 308 | } |
| 309 | reqPath, err = user.JoinPath(reqPath) |
| 310 | if err != nil { |
| 311 | return http.StatusForbidden, err |
| 312 | } |
| 313 | // TODO: return MultiStatus where appropriate. |
| 314 | |
| 315 | // "godoc os RemoveAll" says that "If the path does not exist, RemoveAll |
| 316 | // returns nil (no error)." WebDAV semantics are that it should return a |
| 317 | // "404 Not Found". We therefore have to Stat before we RemoveAll. |
| 318 | if _, err := fs.Get(ctx, reqPath, &fs.GetArgs{}); err != nil { |
| 319 | if errs.IsObjectNotFound(err) { |
| 320 | return http.StatusNotFound, err |
| 321 | } |
| 322 | return http.StatusMethodNotAllowed, err |
| 323 | } |
| 324 | parentPath := path.Dir(reqPath) |
| 325 | parentMeta, err := op.GetNearestMeta(parentPath) |
| 326 | if err != nil && !errors.Is(errors.Cause(err), errs.MetaNotFound) { |
| 327 | return http.StatusInternalServerError, err |
| 328 | } |
| 329 | if !common.CanWrite(user, parentMeta, parentPath) { |
| 330 | return http.StatusForbidden, errs.PermissionDenied |
| 331 | } |
| 332 | if err := fs.Remove(ctx, reqPath); err != nil { |
| 333 | return http.StatusMethodNotAllowed, err |
| 334 | } |
| 335 | //fs.ClearCache(path.Dir(reqPath)) |
| 336 | return http.StatusNoContent, nil |
| 337 | } |
| 338 | |
| 339 | func (h *Handler) handlePut(w http.ResponseWriter, r *http.Request) (status int, err error) { |
| 340 | defer func() { |
no test coverage detected