Skip to content

Commit

Permalink
Really delete things in fs::RecursiveDelete (#7433)
Browse files Browse the repository at this point in the history
* Really delete things in fs::RecursiveDelete
  • Loading branch information
numberZero authored and nerzhul committed Aug 18, 2018
1 parent 4937c50 commit 78bd902
Showing 1 changed file with 21 additions and 34 deletions.
55 changes: 21 additions & 34 deletions src/filesys.cpp
Expand Up @@ -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;
}

Expand Down

0 comments on commit 78bd902

Please sign in to comment.