25
25
* Implementation of CachedDirectory class.
30
#include "drizzled/definitions.h"
32
#include <sys/types.h>
39
#include "drizzled/cached_directory.h"
28
#include "drizzled/global.h"
29
#include "cached_directory.h"
41
31
using namespace std;
46
CachedDirectory::CachedDirectory() :
52
CachedDirectory::CachedDirectory(const string &in_path) :
55
// TODO: Toss future exception
34
CachedDirectory::CachedDirectory(const string &in_path)
56
37
(void) open(in_path);
60
CachedDirectory::CachedDirectory(const string& in_path, set<string>& allowed_exts) :
63
// TODO: Toss future exception
64
(void) open(in_path, allowed_exts);
67
CachedDirectory::CachedDirectory(const string& in_path, enum CachedDirectory::FILTER filter) :
71
// TODO: Toss future exception
72
(void) open(in_path, empty, filter);
76
40
CachedDirectory::~CachedDirectory()
78
for (Entries::iterator p= entries.begin(); p != entries.end(); ++p)
42
Entries::iterator p= entries.begin();
43
while (p != entries.end())
86
51
bool CachedDirectory::open(const string &in_path)
90
return open(in_path, empty);
93
bool CachedDirectory::open(const string &in_path, set<string> &allowed_exts)
95
return open(in_path, allowed_exts, CachedDirectory::NONE);
98
bool CachedDirectory::open(const string &in_path, set<string> &allowed_exts, enum CachedDirectory::FILTER filter)
100
53
DIR *dirp= opendir(in_path.c_str());
127
78
while ((retcode= readdir_r(dirp, &buffer.entry, &result)) == 0 &&
130
std::string buffered_fullpath;
131
if (! allowed_exts.empty())
133
char *ptr= rindex(result->d_name, '.');
137
set<string>::iterator it;
138
it= allowed_exts.find(ptr);
140
if (it != allowed_exts.end())
142
entries.push_back(new Entry(result->d_name));
152
struct stat entrystat;
154
if (result->d_name[0] == '.') // We don't pass back anything hidden at the moment.
157
buffered_fullpath.append(in_path);
158
if (buffered_fullpath[buffered_fullpath.length()] != '/')
159
buffered_fullpath.append(1, FN_LIBCHAR);
161
buffered_fullpath.assign(result->d_name);
163
stat(buffered_fullpath.c_str(), &entrystat);
165
if (S_ISDIR(entrystat.st_mode))
167
entries.push_back(new Entry(result->d_name));
173
struct stat entrystat;
175
buffered_fullpath.append(in_path);
176
if (buffered_fullpath[buffered_fullpath.length()] != '/')
177
buffered_fullpath.append(1, FN_LIBCHAR);
179
buffered_fullpath.assign(result->d_name);
181
stat(buffered_fullpath.c_str(), &entrystat);
183
if (S_ISREG(entrystat.st_mode))
185
entries.push_back(new Entry(result->d_name));
191
entries.push_back(new Entry(result->d_name));
80
entries.push_back(new Entry(result->d_name));
200
85
return error == 0;
203
} /* namespace drizzled */