43#include "BESInternalError.h"
47BESFSDir::BESFSDir(
const string &dirName) :
48 _dirName(dirName), _fileExpr(
""), _dirLoaded(false)
52BESFSDir::BESFSDir(
const string &dirName,
const string &fileExpr) :
53 _dirName(dirName), _fileExpr(fileExpr), _dirLoaded(false)
57BESFSDir::BESFSDir(
const BESFSDir ©From) :
58 _dirName(copyFrom._dirName), _fileExpr(copyFrom._fileExpr), _dirLoaded(false)
66BESFSDir::dirIterator BESFSDir::beginOfDirList()
68 if (_dirLoaded ==
false) {
72 return _dirList.begin();
75BESFSDir::dirIterator BESFSDir::endOfDirList()
77 if (_dirLoaded ==
false) {
81 return _dirList.end();
84BESFSDir::fileIterator BESFSDir::beginOfFileList()
86 if (_dirLoaded ==
false) {
90 return _fileList.begin();
93BESFSDir::fileIterator BESFSDir::endOfFileList()
95 if (_dirLoaded ==
false) {
99 return _fileList.end();
102void BESFSDir::loadDir()
110 if ((dip = opendir(_dirName.c_str())) == NULL) {
111 string err_str =
"ERROR: failed to open directory '" + _dirName +
"'";
112 throw BESError(err_str, BES_NOT_FOUND_ERROR, __FILE__, __LINE__);
117 while ((dit = readdir(dip)) != NULL) {
119 string dirEntry = dit->d_name;
120 if (dirEntry !=
"." && dirEntry !=
"..") {
121 string fullPath = _dirName +
"/" + dirEntry;
133 if (-1 == stat(fullPath.c_str(), &buf))
137 throw BESError(
string(
"Did not find the path: '") + fullPath +
"'", BES_NOT_FOUND_ERROR,
142 if (S_ISDIR(buf.st_mode)) {
143 _dirList.push_back(BESFSDir(fullPath));
146 if (_fileExpr !=
"") {
147 BESRegex reg_expr(_fileExpr.c_str());
148 int match_ret = reg_expr.match(dirEntry.c_str(), dirEntry.size());
149 if (match_ret ==
static_cast<int>(dirEntry.size())) {
150 _fileList.push_back(BESFSFile(_dirName, dirEntry));
154 _fileList.push_back(BESFSFile(_dirName, dirEntry));