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];
130 while ((retcode= readdir_r(dirp, &buffer.entry, &result)) == 0 &&
133 std::string buffered_fullpath;
134 if (not allowed_exts.empty())
136 char *ptr= rindex(result->d_name,
'.');
137 if (ptr && allowed_exts.count(ptr))
139 entries.push_back(
new Entry(result->d_name));
148 struct stat entrystat;
150 if (result->d_name[0] ==
'.')
155 buffered_fullpath.append(in_path);
156 if (buffered_fullpath[buffered_fullpath.length()] !=
'/')
157 buffered_fullpath.append(1, FN_LIBCHAR);
160 buffered_fullpath.append(result->d_name);
162 int err= stat(buffered_fullpath.c_str(), &entrystat);
166 errmsg_printf(error::WARN, ER(ER_CANT_GET_STAT),
167 buffered_fullpath.c_str(),
171 if (err == 0 && S_ISDIR(entrystat.st_mode))
173 entries.push_back(
new Entry(result->d_name));
179 struct stat entrystat;
181 buffered_fullpath.append(in_path);
182 if (buffered_fullpath[buffered_fullpath.length() - 1] !=
'/')
183 buffered_fullpath.append(1, FN_LIBCHAR);
185 buffered_fullpath= result->d_name;
187 stat(buffered_fullpath.c_str(), &entrystat);
189 if (S_ISREG(entrystat.st_mode))
191 entries.push_back(
new Entry(result->d_name));
197 entries.push_back(
new Entry(result->d_name));
209 std::ostream& operator<<(std::ostream& output,
const CachedDirectory &directory)
211 output <<
"CachedDirectory:(Path: " << directory.
getPath() <<
")\n";
213 output <<
"\t(" << iter->filename <<
")\n";