X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Ffilesys.cpp;h=8248a13d46f3703c48061faa68f3b2e150289f8e;hb=e0329a3caee863a2302748f710401bfc0dfa78db;hp=a2d3f9d145c2388da2db27ca7aa2c298f704c15f;hpb=d38ac3aae3340beffb44cdd78a8dfd52828ec503;p=dragonfireclient.git diff --git a/src/filesys.cpp b/src/filesys.cpp index a2d3f9d14..8248a13d4 100644 --- a/src/filesys.cpp +++ b/src/filesys.cpp @@ -18,7 +18,9 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "filesys.h" +#include "strfnd.h" #include +#include namespace fs { @@ -77,10 +79,15 @@ std::vector GetDirListing(std::string pathstring) } else { + // NOTE: + // Be very sure to not include '..' in the results, it will + // result in an epic failure when deleting stuff. + DirListNode node; node.name = FindFileData.cFileName; node.dir = FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; - listing.push_back(node); + if(node.name != "." && node.name != "..") + listing.push_back(node); // List all the other files in the directory. while (FindNextFile(hFind, &FindFileData) != 0) @@ -88,7 +95,8 @@ std::vector GetDirListing(std::string pathstring) DirListNode node; node.name = FindFileData.cFileName; node.dir = FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; - listing.push_back(node); + if(node.name != "." && node.name != "..") + listing.push_back(node); } dwError = GetLastError(); @@ -130,12 +138,39 @@ bool PathExists(std::string path) return (GetFileAttributes(path.c_str()) != INVALID_FILE_ATTRIBUTES); } +bool RecursiveDelete(std::string path) +{ + std::cerr<<"Removing \""< #include #include #include +#include std::vector GetDirListing(std::string pathstring) { @@ -149,12 +184,16 @@ std::vector GetDirListing(std::string pathstring) } while ((dirp = readdir(dp)) != NULL) { + // NOTE: + // Be very sure to not include '..' in the results, it will + // result in an epic failure when deleting stuff. if(dirp->d_name[0]!='.'){ DirListNode node; node.name = dirp->d_name; if(dirp->d_type == DT_DIR) node.dir = true; else node.dir = false; - listing.push_back(node); + if(node.name != "." && node.name != "..") + listing.push_back(node); } } closedir(dp); @@ -184,7 +223,91 @@ bool PathExists(std::string path) return (stat(path.c_str(),&st) == 0); } +bool RecursiveDelete(std::string path) +{ + /* + Execute the 'rm' command directly, by fork() and execve() + */ + + std::cerr<<"Removing \""< list = GetDirListing(path); + for(unsigned int i=0; i tocreate; + std::string basepath = path; + while(!PathExists(basepath)) + { + tocreate.push_back(basepath); + pos = basepath.rfind('/'); + if(pos == std::string::npos) + return false; + basepath = basepath.substr(0,pos); + } + for(int i=tocreate.size()-1;i>=0;i--) + CreateDir(tocreate[i]); + return true; +} + } // namespace fs