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.
33
#include "drizzled/cached_directory.h"
40
CachedDirectory::CachedDirectory() :
46
CachedDirectory::CachedDirectory(const string &in_path) :
49
// TODO: Toss future exception
54
CachedDirectory::CachedDirectory(const string& in_path, set<string>& allowed_exts) :
57
// TODO: Toss future exception
58
(void) open(in_path, allowed_exts);
62
CachedDirectory::~CachedDirectory()
64
for (Entries::iterator p= entries.begin(); p != entries.end(); ++p)
72
bool CachedDirectory::open(const string &in_path)
76
return open(in_path, empty);
79
bool CachedDirectory::open(const string &in_path, set<string> &allowed_exts)
81
DIR *dirp= opendir(in_path.c_str());
95
* The readdir_r() call on Solaris operates a bit differently from other
96
* systems in that the dirent structure must be allocated along with enough
97
* space to contain the filename (see man page for readdir_r on Solaris).
98
* Instead of dynamically try to allocate this buffer, just set the max
99
* name for a path instead.
101
char space[sizeof(dirent) + PATH_MAX + 1];
108
while ((retcode= readdir_r(dirp, &buffer.entry, &result)) == 0 &&
111
if (! allowed_exts.empty())
113
char *ptr= rindex(result->d_name, '.');
117
set<string>::iterator it;
118
it= allowed_exts.find(ptr);
120
if (it != allowed_exts.end())
122
entries.push_back(new Entry(result->d_name));
128
entries.push_back(new Entry(result->d_name));
138
} /* namespace drizzled */