forked from Mirrorlandia_minetest/minetest
Really delete things in fs::RecursiveDelete (#7433)
* Really delete things in fs::RecursiveDelete
This commit is contained in:
parent
4937c5007f
commit
78bd902b9f
@ -125,45 +125,32 @@ bool IsDirDelimiter(char c)
|
|||||||
|
|
||||||
bool RecursiveDelete(const std::string &path)
|
bool RecursiveDelete(const std::string &path)
|
||||||
{
|
{
|
||||||
infostream<<"Recursively deleting \""<<path<<"\""<<std::endl;
|
infostream << "Recursively deleting \"" << path << "\"" << std::endl;
|
||||||
|
if (!IsDir(path)) {
|
||||||
DWORD attr = GetFileAttributes(path.c_str());
|
infostream << "RecursiveDelete: Deleting file " << path << std::endl;
|
||||||
bool is_directory = (attr != INVALID_FILE_ATTRIBUTES &&
|
if (!DeleteFile(path.c_str())) {
|
||||||
(attr & FILE_ATTRIBUTE_DIRECTORY));
|
errorstream << "RecursiveDelete: Failed to delete file "
|
||||||
if(!is_directory)
|
<< path << std::endl;
|
||||||
{
|
return false;
|
||||||
infostream<<"RecursiveDelete: Deleting file "<<path<<std::endl;
|
}
|
||||||
//bool did = DeleteFile(path.c_str());
|
return true;
|
||||||
bool did = true;
|
}
|
||||||
if(!did){
|
infostream << "RecursiveDelete: Deleting content of directory "
|
||||||
errorstream<<"RecursiveDelete: Failed to delete file "
|
<< path << std::endl;
|
||||||
<<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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
infostream << "RecursiveDelete: Deleting directory " << path << std::endl;
|
||||||
{
|
if (!RemoveDirectory(path.c_str())) {
|
||||||
infostream<<"RecursiveDelete: Deleting content of directory "
|
errorstream << "Failed to recursively delete directory "
|
||||||
<<path<<std::endl;
|
<< path << std::endl;
|
||||||
std::vector<DirListNode> content = GetDirListing(path);
|
return false;
|
||||||
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;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user