File/Directory Enhancement

- Migrated enhanced code out of taskd.
This commit is contained in:
Paul Beckingham
2011-04-16 00:44:07 -04:00
parent e9273cd6c3
commit 87c285e6b2
5 changed files with 234 additions and 20 deletions

View File

@@ -30,7 +30,7 @@
#include <sys/types.h>
#include <dirent.h>
#include <string.h>
#include "Directory.h"
#include <Directory.h>
#include "../cmake.h"
////////////////////////////////////////////////////////////////////////////////
@@ -87,7 +87,41 @@ bool Directory::create ()
////////////////////////////////////////////////////////////////////////////////
bool Directory::remove ()
{
return rmdir (data.c_str ()) == 0 ? true : false;
return remove_directory (data);
}
////////////////////////////////////////////////////////////////////////////////
bool Directory::remove_directory (const std::string& dir)
{
DIR* dp = opendir (dir.c_str ());
if (dp != NULL)
{
struct dirent* de;
while ((de = readdir (dp)) != NULL)
{
if (!strcmp (de->d_name, ".") ||
!strcmp (de->d_name, ".."))
continue;
#if defined (SOLARIS) || defined (HAIKU)
struct stat s;
stat (de->d_name, &s);
if (s.st_mode & S_IFDIR)
remove_directory (dir + "/" + de->de_name);
else
unlink ((dir + "/" + de->d_name).c_str ());
#else
if (de->d_type == DT_DIR)
remove_directory (dir + "/" + de->d_name);
else
unlink ((dir + "/" + de->d_name).c_str ());
#endif
}
closedir (dp);
}
return rmdir (dir.c_str ()) ? false : true;
}
////////////////////////////////////////////////////////////////////////////////