25
25
* Implementation of CachedDirectory class.
30
#include <sys/types.h>
37
#include "drizzled/cached_directory.h"
28
#include "drizzled/global.h"
29
#include "cached_directory.h"
39
31
using namespace std;
44
CachedDirectory::CachedDirectory() :
50
CachedDirectory::CachedDirectory(const string &in_path) :
53
// TODO: Toss future exception
34
CachedDirectory::CachedDirectory(const string &in_path)
54
37
(void) open(in_path);
58
CachedDirectory::CachedDirectory(const string& in_path, set<string>& allowed_exts) :
61
// TODO: Toss future exception
62
(void) open(in_path, allowed_exts);
65
CachedDirectory::CachedDirectory(const string& in_path, enum CachedDirectory::FILTER filter) :
69
// TODO: Toss future exception
70
(void) open(in_path, empty, filter);
74
40
CachedDirectory::~CachedDirectory()
76
for (Entries::iterator p= entries.begin(); p != entries.end(); ++p)
42
Entries::iterator p= entries.begin();
43
while (p != entries.end())
84
51
bool CachedDirectory::open(const string &in_path)
88
return open(in_path, empty);
91
bool CachedDirectory::open(const string &in_path, set<string> &allowed_exts)
93
return open(in_path, allowed_exts, CachedDirectory::NONE);
96
bool CachedDirectory::open(const string &in_path, set<string> &allowed_exts, enum CachedDirectory::FILTER filter)
98
53
DIR *dirp= opendir(in_path.c_str());
125
78
while ((retcode= readdir_r(dirp, &buffer.entry, &result)) == 0 &&
128
if (! allowed_exts.empty())
130
char *ptr= rindex(result->d_name, '.');
134
set<string>::iterator it;
135
it= allowed_exts.find(ptr);
137
if (it != allowed_exts.end())
139
entries.push_back(new Entry(result->d_name));
149
struct stat entrystat;
151
if (result->d_name[0] == '.')
154
stat(result->d_name, &entrystat);
156
if (S_ISDIR(entrystat.st_mode))
158
entries.push_back(new Entry(result->d_name));
164
struct stat entrystat;
166
stat(result->d_name, &entrystat);
168
if (S_ISREG(entrystat.st_mode))
170
entries.push_back(new Entry(result->d_name));
176
entries.push_back(new Entry(result->d_name));
80
entries.push_back(new Entry(result->d_name));
185
85
return error == 0;
188
} /* namespace drizzled */