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
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) :
55
// TODO: Toss future exception
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
CachedDirectory::~CachedDirectory()
78
for (Entries::iterator p= entries.begin(); p != entries.end(); ++p)
86
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
DIR *dirp= opendir(in_path.c_str());
114
* The readdir_r() call on Solaris operates a bit differently from other
115
* systems in that the dirent structure must be allocated along with enough
116
* space to contain the filename (see man page for readdir_r on Solaris).
117
* Instead of dynamically try to allocate this buffer, just set the max
118
* name for a path instead.
120
char space[sizeof(dirent) + PATH_MAX + 1];
127
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));
203
} /* namespace drizzled */