1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
* Implementation of CachedDirectory class.
30
#include <drizzled/definitions.h>
32
#include <sys/types.h>
39
#include <drizzled/cached_directory.h>
46
CachedDirectory::CachedDirectory() :
52
CachedDirectory::CachedDirectory(const string &in_path) :
56
// TODO: Toss future exception
61
CachedDirectory::CachedDirectory(const string& in_path, set<string>& allowed_exts) :
65
// TODO: Toss future exception
66
(void) open(in_path, allowed_exts);
69
CachedDirectory::CachedDirectory(const string& in_path, enum CachedDirectory::FILTER filter, bool use_full_path_arg) :
71
use_full_path(use_full_path_arg)
74
// TODO: Toss future exception
75
(void) open(in_path, empty, filter);
79
CachedDirectory::~CachedDirectory()
81
for (Entries::iterator iter= entries.begin(); iter != entries.end(); ++iter)
88
bool CachedDirectory::open(const string &in_path)
92
return open(in_path, empty);
95
bool CachedDirectory::open(const string &in_path, set<string> &allowed_exts)
97
return open(in_path, allowed_exts, CachedDirectory::NONE);
100
bool CachedDirectory::open(const string &in_path, set<string> &allowed_exts, enum CachedDirectory::FILTER filter)
102
DIR *dirp= opendir(in_path.c_str());
116
* The readdir_r() call on Solaris operates a bit differently from other
117
* systems in that the dirent structure must be allocated along with enough
118
* space to contain the filename (see man page for readdir_r on Solaris).
119
* Instead of dynamically try to allocate this buffer, just set the max
120
* name for a path instead.
122
char space[sizeof(dirent) + PATH_MAX + 1];
129
while ((retcode= readdir_r(dirp, &buffer.entry, &result)) == 0 &&
132
std::string buffered_fullpath;
133
if (not allowed_exts.empty())
135
char *ptr= rindex(result->d_name, '.');
139
set<string>::iterator it;
140
it= allowed_exts.find(ptr);
142
if (it != allowed_exts.end())
144
entries.push_back(new Entry(result->d_name));
154
struct stat entrystat;
156
if (result->d_name[0] == '.') // We don't pass back anything hidden at the moment.
161
buffered_fullpath.append(in_path);
162
if (buffered_fullpath[buffered_fullpath.length()] != '/')
163
buffered_fullpath.append(1, FN_LIBCHAR);
166
buffered_fullpath.append(result->d_name);
168
stat(buffered_fullpath.c_str(), &entrystat);
170
if (S_ISDIR(entrystat.st_mode))
172
entries.push_back(new Entry(result->d_name));
178
struct stat entrystat;
180
buffered_fullpath.append(in_path);
181
if (buffered_fullpath[buffered_fullpath.length()] != '/')
182
buffered_fullpath.append(1, FN_LIBCHAR);
184
buffered_fullpath.assign(result->d_name);
186
stat(buffered_fullpath.c_str(), &entrystat);
188
if (S_ISREG(entrystat.st_mode))
190
entries.push_back(new Entry(result->d_name));
196
entries.push_back(new Entry(result->d_name));
208
} /* namespace drizzled */