| 1467 | } |
| 1468 | |
| 1469 | static dav_error * dav_fs_remove_resource(dav_resource *resource, |
| 1470 | dav_response **response) |
| 1471 | { |
| 1472 | apr_status_t status; |
| 1473 | dav_resource_private *info = resource->info; |
| 1474 | |
| 1475 | *response = NULL; |
| 1476 | |
| 1477 | /* if a collection, recursively remove it and its children, |
| 1478 | * including the state dirs |
| 1479 | */ |
| 1480 | if (resource->collection) { |
| 1481 | dav_walk_params params = { 0 }; |
| 1482 | dav_error *err = NULL; |
| 1483 | dav_response *multi_status; |
| 1484 | |
| 1485 | params.walk_type = (DAV_WALKTYPE_NORMAL |
| 1486 | | DAV_WALKTYPE_HIDDEN |
| 1487 | | DAV_WALKTYPE_POSTFIX); |
| 1488 | params.func = dav_fs_delete_walker; |
| 1489 | params.pool = info->pool; |
| 1490 | params.root = resource; |
| 1491 | |
| 1492 | if ((err = dav_fs_walk(¶ms, DAV_INFINITY, |
| 1493 | &multi_status)) != NULL) { |
| 1494 | /* on a "real" error, then just punt. nothing else to do. */ |
| 1495 | return err; |
| 1496 | } |
| 1497 | |
| 1498 | if ((*response = multi_status) != NULL) { |
| 1499 | /* some multistatus responses exist. wrap them in a 207 */ |
| 1500 | return dav_new_error(info->pool, HTTP_MULTI_STATUS, 0, 0, |
| 1501 | "Error(s) occurred on some resources during " |
| 1502 | "the deletion process."); |
| 1503 | } |
| 1504 | |
| 1505 | /* no errors... update resource state */ |
| 1506 | resource->exists = 0; |
| 1507 | resource->collection = 0; |
| 1508 | |
| 1509 | return NULL; |
| 1510 | } |
| 1511 | |
| 1512 | /* not a collection; remove the file and its properties */ |
| 1513 | if ((status = apr_file_remove(info->pathname, info->pool)) != APR_SUCCESS) { |
| 1514 | if (APR_STATUS_IS_ENOENT(status)) { |
| 1515 | /* Return a 404 if there is a race with another DELETE, |
| 1516 | * per RFC 4918§9.6. */ |
| 1517 | return dav_new_error(info->pool, HTTP_NOT_FOUND, 0, status, |
| 1518 | "Cannot remove already-removed resource."); |
| 1519 | } |
| 1520 | else { |
| 1521 | return dav_new_error(info->pool, HTTP_FORBIDDEN, 0, status, |
| 1522 | "Cannot remove resource"); |
| 1523 | } |
| 1524 | } |
| 1525 | |
| 1526 | /* update resource state */ |
nothing calls this directly
no test coverage detected