32 #include <boost/foreach.hpp>
33 #include <sys/types.h>
41 #include <drizzled/util/find_ptr.h>
42 #include <drizzled/error_t.h>
43 #include <drizzled/error.h>
44 #include <drizzled/errmsg_print.h>
47 using namespace drizzled;
51 CachedDirectory::CachedDirectory() :
71 (void)
open(in_path, allowed_exts);
76 use_full_path(use_full_path_arg)
80 (void)
open(in_path, empty, filter);
86 BOOST_FOREACH(Entries::reference iter,
entries)
93 return open(in_path, empty);
98 return open(in_path, allowed_exts, CachedDirectory::NONE);
101 bool CachedDirectory::open(
const string &in_path, set<string> &allowed_exts,
enum CachedDirectory::FILTER filter)
103 DIR *dirp= opendir(in_path.c_str());
123 char space[
sizeof(dirent) + PATH_MAX + 1];
127 char space[
sizeof(dirent) + UCHAR_MAX + 1];
134 while ((retcode= readdir_r(dirp, &buffer.entry, &result)) == 0 &&
137 std::string buffered_fullpath;
138 if (not allowed_exts.empty())
140 char *ptr= rindex(result->d_name,
'.');
141 if (ptr && allowed_exts.count(ptr))
143 entries.push_back(
new Entry(result->d_name));
152 struct stat entrystat;
154 if (result->d_name[0] ==
'.')
159 buffered_fullpath.append(in_path);
160 if (buffered_fullpath[buffered_fullpath.length()] !=
'/')
161 buffered_fullpath.append(1, FN_LIBCHAR);
164 buffered_fullpath.append(result->d_name);
166 int err= stat(buffered_fullpath.c_str(), &entrystat);
170 errmsg_printf(error::WARN, ER(ER_CANT_GET_STAT),
171 buffered_fullpath.c_str(),
175 if (err == 0 && S_ISDIR(entrystat.st_mode))
177 entries.push_back(
new Entry(result->d_name));
183 struct stat entrystat;
185 buffered_fullpath.append(in_path);
186 if (buffered_fullpath[buffered_fullpath.length() - 1] !=
'/')
187 buffered_fullpath.append(1, FN_LIBCHAR);
189 buffered_fullpath= result->d_name;
191 stat(buffered_fullpath.c_str(), &entrystat);
193 if (S_ISREG(entrystat.st_mode))
195 entries.push_back(
new Entry(result->d_name));
201 entries.push_back(
new Entry(result->d_name));
213 std::ostream& operator<<(std::ostream& output,
const CachedDirectory &directory)
215 output <<
"CachedDirectory:(Path: " << directory.
getPath() <<
")\n";
217 output <<
"\t(" << iter->filename <<
")\n";