MCPcopy Create free account
hub / github.com/TactilityProject/Tactility / deleteRecursively

Function deleteRecursively

TactilityCore/Source/file/File.cpp:306–336  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

304}
305
306bool 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
338bool deleteFile(const std::string& path) {
339 auto lock = getLock(path)->asScopedLock();

Callers 7

handleFsDeleteMethod · 0.85
cleanupInstallDirectoryFunction · 0.85
installFunction · 0.85
uninstallFunction · 0.85
copyRecursiveFunction · 0.85
onResultMethod · 0.85
doPasteMethod · 0.85

Calls 7

isDirectoryFunction · 0.85
scandirFunction · 0.85
deleteDirectoryFunction · 0.85
isFileFunction · 0.85
deleteFileFunction · 0.85
errorMethod · 0.80
infoMethod · 0.80

Tested by

no test coverage detected