Little fixes

This commit is contained in:
Perttu Ahola 2011-01-26 00:49:32 +02:00
parent 9f882bf74d
commit b456821680

@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
#include "filesys.h"
#include "strfnd.h"
#include <iostream>
#include <string.h>
@ -78,9 +79,14 @@ std::vector<DirListNode> 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;
if(node.name != "." && node.name != "..")
listing.push_back(node);
// List all the other files in the directory.
@ -89,6 +95,7 @@ std::vector<DirListNode> GetDirListing(std::string pathstring)
DirListNode node;
node.name = FindFileData.cFileName;
node.dir = FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
if(node.name != "." && node.name != "..")
listing.push_back(node);
}
@ -135,7 +142,7 @@ bool RecursiveDelete(std::string path)
{
std::cerr<<"Removing \""<<path<<"\""<<std::endl;
return false;
//return false;
// This silly function needs a double-null terminated string...
// Well, we'll just make sure it has at least two, then.
@ -173,11 +180,15 @@ std::vector<DirListNode> 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;
if(node.name != "." && node.name != "..")
listing.push_back(node);
}
}
@ -262,6 +273,8 @@ bool RecursiveDeleteContent(std::string path)
std::vector<DirListNode> list = GetDirListing(path);
for(unsigned int i=0; i<list.size(); i++)
{
if(trim(list[i].name) == "." || trim(list[i].name) == "..")
continue;
std::string childpath = path + "/" + list[i].name;
bool r = RecursiveDelete(childpath);
if(r == false)