25
25
* Implementation of CachedDirectory class.
30
#include <sys/types.h>
37
#include "drizzled/cached_directory.h"
28
#include "cached_directory.h"
39
30
using namespace std;
44
CachedDirectory::CachedDirectory() :
50
CachedDirectory::CachedDirectory(const string &in_path) :
53
// TODO: Toss future exception
33
CachedDirectory::CachedDirectory(const string &in_path)
54
36
(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
39
CachedDirectory::~CachedDirectory()
76
for (Entries::iterator p= entries.begin(); p != entries.end(); ++p)
41
Entries::iterator p= entries.begin();
42
while (p != entries.end())
84
50
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
DIR *dirp= opendir(in_path.c_str());
55
if ((dirp= opendir(in_path.c_str())) == NULL)
62
* The readdir_r() call on Solaris operates a bit differently from other
63
* systems in that the dirent structure must be allocated along with enough
64
* space to contain the filename (see man page for readdir_r on Solaris).
112
* The readdir_r() call on Solaris operates a bit differently from other
113
* systems in that the dirent structure must be allocated along with enough
114
* space to contain the filename (see man page for readdir_r on Solaris).
115
* Instead of dynamically try to allocate this buffer, just set the max
116
* name for a path instead.
118
char space[sizeof(dirent) + PATH_MAX + 1];
68
size= sizeof(dirent) + pathconf(in_path.c_str(), _PC_NAME_MAX);
73
dirent *entry= (dirent *) malloc(size);
125
while ((retcode= readdir_r(dirp, &buffer.entry, &result)) == 0 &&
85
retcode= readdir_r(dirp, entry, &result);
86
while ((retcode == 0) && (result != NULL))
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));
88
entries.push_back(new Entry(entry->d_name));
89
retcode= readdir_r(dirp, entry, &result);
185
97
return error == 0;
188
} /* namespace drizzled */