From b4568216804215af4ef7e511f988044188d581aa Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Wed, 26 Jan 2011 00:49:32 +0200 Subject: Little fixes --- src/filesys.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/filesys.cpp') diff --git a/src/filesys.cpp b/src/filesys.cpp index a025ec185..2fd90c237 100644 --- a/src/filesys.cpp +++ b/src/filesys.cpp @@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "filesys.h" +#include "strfnd.h" #include #include @@ -78,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) @@ -89,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(); @@ -135,7 +142,7 @@ bool RecursiveDelete(std::string path) { std::cerr<<"Removing \""< 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); @@ -262,7 +273,9 @@ bool RecursiveDeleteContent(std::string path) std::vector list = GetDirListing(path); for(unsigned int i=0; i