| 304 | } |
| 305 | |
| 306 | bool deleteRecursively(const std::string& path) { |
| 307 | if (path.empty()) { |
| 308 | return true; |
| 309 | } |
| 310 | |
| 311 | if (isDirectory(path)) { |
| 312 | std::vector<dirent> entries; |
| 313 | if (scandir(path, entries) < 0) { |
| 314 | LOGGER.error("Failed to scan directory {}", path); |
| 315 | return false; |
| 316 | } |
| 317 | |
| 318 | for (const auto& entry : entries) { |
| 319 | auto child_path = path + "/" + entry.d_name; |
| 320 | if (!deleteRecursively(child_path)) { |
| 321 | return false; |
| 322 | } |
| 323 | } |
| 324 | LOGGER.info("Deleting {}", path); |
| 325 | return deleteDirectory(path); |
| 326 | } else if (isFile(path)) { |
| 327 | LOGGER.info("Deleting {}", path); |
| 328 | return deleteFile(path); |
| 329 | } else if (path == "/" || path == "." || path == "..") { |
| 330 | // No-op |
| 331 | return true; |
| 332 | } else { |
| 333 | LOGGER.error("Failed to delete \"{}\": unknown type", path); |
| 334 | return false; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | bool deleteFile(const std::string& path) { |
| 339 | auto lock = getLock(path)->asScopedLock(); |
no test coverage detected