From 4047be93db90c948b7e8b15fb351dcd92407d9a7 Mon Sep 17 00:00:00 2001 From: Maksim Date: Tue, 17 May 2022 13:23:54 +0300 Subject: [PATCH] Use built-in methods for deletion in RecursiveDelete --- src/filesys.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/filesys.cpp b/src/filesys.cpp index 191345b97..984fc6bb7 100644 --- a/src/filesys.cpp +++ b/src/filesys.cpp @@ -286,12 +286,13 @@ bool IsDirDelimiter(char c) bool RecursiveDelete(const std::string &path) { + infostream<<"Removing \""< paths; + paths.push_back(path); + fs::GetRecursiveSubPaths(path, paths, true, {}); + + // Go backwards to successfully delete the output of GetRecursiveSubPaths + for (int i = paths.size() - 1; i >= 0; i--) { + const std::string &p = paths[i]; + bool did = DeleteSingleFileOrEmptyDirectory(p); + if (!did) { + errorstream << "Failed to delete " << p << std::endl; + success = false; + } + } + + return success; +#endif } bool DeleteSingleFileOrEmptyDirectory(const std::string &path)