| 393 | // ── DELETE ─────────────────────────────────────────────────────────────────── |
| 394 | |
| 395 | void WebDAVHandler::handleDelete(WebServer& s) { |
| 396 | String path = getRequestPath(s); |
| 397 | LOG_DBG("DAV", "DELETE %s", path.c_str()); |
| 398 | |
| 399 | if (path == "/" || path.isEmpty()) { |
| 400 | s.send(403, "text/plain", "Cannot delete root"); |
| 401 | return; |
| 402 | } |
| 403 | |
| 404 | if (isProtectedPath(path)) { |
| 405 | s.send(403, "text/plain", "Forbidden"); |
| 406 | return; |
| 407 | } |
| 408 | |
| 409 | if (!Storage.exists(path.c_str())) { |
| 410 | s.send(404, "text/plain", "Not Found"); |
| 411 | return; |
| 412 | } |
| 413 | |
| 414 | HalFile file = Storage.open(path.c_str()); |
| 415 | if (!file) { |
| 416 | s.send(500, "text/plain", "Failed to open"); |
| 417 | return; |
| 418 | } |
| 419 | |
| 420 | if (file.isDirectory()) { |
| 421 | // Check if directory is empty |
| 422 | HalFile entry = file.openNextFile(); |
| 423 | if (entry) { |
| 424 | entry.close(); |
| 425 | file.close(); |
| 426 | s.send(409, "text/plain", "Directory not empty"); |
| 427 | return; |
| 428 | } |
| 429 | file.close(); |
| 430 | if (Storage.rmdir(path.c_str())) { |
| 431 | s.send(204); |
| 432 | } else { |
| 433 | s.send(500, "text/plain", "Failed to remove directory"); |
| 434 | } |
| 435 | } else { |
| 436 | file.close(); |
| 437 | clearBookCache(path.c_str()); |
| 438 | if (Storage.remove(path.c_str())) { |
| 439 | s.send(204); |
| 440 | } else { |
| 441 | s.send(500, "text/plain", "Failed to delete file"); |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | // ── MKCOL ──────────────────────────────────────────────────────────────────── |
| 447 |
nothing calls this directly
no test coverage detected