33 #include <sys/types.h> 43 #include "BESInternalError.h" 45 BESFSDir::BESFSDir(
const string &dirName) :
46 _dirName(dirName), _fileExpr(
""), _dirLoaded(false)
50 BESFSDir::BESFSDir(
const string &dirName,
const string &fileExpr) :
51 _dirName(dirName), _fileExpr(fileExpr), _dirLoaded(false)
55 BESFSDir::BESFSDir(
const BESFSDir ©From) :
56 _dirName(copyFrom._dirName), _fileExpr(copyFrom._fileExpr), _dirLoaded(false)
64 BESFSDir::dirIterator BESFSDir::beginOfDirList()
66 if (_dirLoaded ==
false) {
70 return _dirList.begin();
73 BESFSDir::dirIterator BESFSDir::endOfDirList()
75 if (_dirLoaded ==
false) {
79 return _dirList.end();
82 BESFSDir::fileIterator BESFSDir::beginOfFileList()
84 if (_dirLoaded ==
false) {
88 return _fileList.begin();
91 BESFSDir::fileIterator BESFSDir::endOfFileList()
93 if (_dirLoaded ==
false) {
97 return _fileList.end();
100 void BESFSDir::loadDir()
108 if ((dip = opendir(_dirName.c_str())) == NULL) {
109 string err_str =
"ERROR: failed to open directory '" + _dirName +
"'";
110 throw BESError(err_str, BES_NOT_FOUND_ERROR, __FILE__, __LINE__);
115 while ((dit = readdir(dip)) != NULL) {
117 string dirEntry = dit->d_name;
118 if (dirEntry !=
"." && dirEntry !=
"..") {
119 string fullPath = _dirName +
"/" + dirEntry;
131 if (-1 == stat(fullPath.c_str(), &buf))
135 throw BESError(
string(
"Did not find the path: '") + fullPath +
"'", BES_NOT_FOUND_ERROR,
140 if (S_ISDIR(buf.st_mode)) {
141 _dirList.push_back(
BESFSDir(fullPath));
144 if (_fileExpr !=
"") {
145 BESRegex reg_expr(_fileExpr.c_str());
146 int match_ret = reg_expr.
match(dirEntry.c_str(), dirEntry.length());
147 if (match_ret == static_cast<int>(dirEntry.length())) {
148 _fileList.push_back(
BESFSFile(_dirName, dirEntry));
152 _fileList.push_back(
BESFSFile(_dirName, dirEntry));
int match(const char *s, int len, int pos=0)
Does the pattern match.
Abstract exception class for the BES with basic string message.