aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVitaliy <silverunicorn2011@yandex.ru>2018-08-18 12:00:06 +0300
committerLoïc Blot <nerzhul@users.noreply.github.com>2018-08-18 11:00:06 +0200
commit78bd902b9f770dee9b4d41f03c289574e6b59151 (patch)
treebff9d3554f97179dd55028ba7420dd56e980e606 /src
parent4937c5007fcb4bf210f6104919b744d1baa46d93 (diff)
downloadminetest-78bd902b9f770dee9b4d41f03c289574e6b59151.tar.gz
minetest-78bd902b9f770dee9b4d41f03c289574e6b59151.tar.bz2
minetest-78bd902b9f770dee9b4d41f03c289574e6b59151.zip
Really delete things in fs::RecursiveDelete (#7433)
* Really delete things in fs::RecursiveDelete
Diffstat (limited to 'src')
-rw-r--r--src/filesys.cpp55
1 files changed, 21 insertions, 34 deletions
diff --git a/src/filesys.cpp b/src/filesys.cpp
index f961dedc6..be61ba430 100644
--- a/src/filesys.cpp
+++ b/src/filesys.cpp
@@ -125,46 +125,33 @@ bool IsDirDelimiter(char c)
bool RecursiveDelete(const std::string &path)
{
- infostream<<"Recursively deleting \""<<path<<"\""<<std::endl;
-
- DWORD attr = GetFileAttributes(path.c_str());
- bool is_directory = (attr != INVALID_FILE_ATTRIBUTES &&
- (attr & FILE_ATTRIBUTE_DIRECTORY));
- if(!is_directory)
- {
- infostream<<"RecursiveDelete: Deleting file "<<path<<std::endl;
- //bool did = DeleteFile(path.c_str());
- bool did = true;
- if(!did){
- errorstream<<"RecursiveDelete: Failed to delete file "
- <<path<<std::endl;
+ infostream << "Recursively deleting \"" << path << "\"" << std::endl;
+ if (!IsDir(path)) {
+ infostream << "RecursiveDelete: Deleting file " << path << std::endl;
+ if (!DeleteFile(path.c_str())) {
+ errorstream << "RecursiveDelete: Failed to delete file "
+ << path << std::endl;
return false;
}
+ return true;
}
- else
- {
- infostream<<"RecursiveDelete: Deleting content of directory "
- <<path<<std::endl;
- std::vector<DirListNode> content = GetDirListing(path);
- for(size_t i=0; i<content.size(); i++){
- const DirListNode &n = content[i];
- std::string fullpath = path + DIR_DELIM + n.name;
- bool did = RecursiveDelete(fullpath);
- if(!did){
- errorstream<<"RecursiveDelete: Failed to recurse to "
- <<fullpath<<std::endl;
- return false;
- }
- }
- infostream<<"RecursiveDelete: Deleting directory "<<path<<std::endl;
- //bool did = RemoveDirectory(path.c_str();
- bool did = true;
- if(!did){
- errorstream<<"Failed to recursively delete directory "
- <<path<<std::endl;
+ infostream << "RecursiveDelete: Deleting content of directory "
+ << path << std::endl;
+ std::vector<DirListNode> content = GetDirListing(path);
+ for (const DirListNode &n: content) {
+ std::string fullpath = path + DIR_DELIM + n.name;
+ if (!RecursiveDelete(fullpath)) {
+ errorstream << "RecursiveDelete: Failed to recurse to "
+ << fullpath << std::endl;
return false;
}
}
+ infostream << "RecursiveDelete: Deleting directory " << path << std::endl;
+ if (!RemoveDirectory(path.c_str())) {
+ errorstream << "Failed to recursively delete directory "
+ << path << std::endl;
+ return false;
+ }
return true;
}