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()
107 if ((dip = opendir(_dirName.c_str())) == NULL) {
108 string err_str =
"ERROR: failed to open directory '" + _dirName +
"'";
109 throw BESError(err_str, BES_NOT_FOUND_ERROR, __FILE__, __LINE__);
114 while ((dit = readdir(dip)) != NULL) {
116 string dirEntry = dit->d_name;
117 if (dirEntry !=
"." && dirEntry !=
"..") {
118 string fullPath = _dirName +
"/" + dirEntry;
119 if (-1 == stat(fullPath.c_str(), &buf))
120 throw BESError(
string(
"Did not find the path: '") + fullPath +
"'", BES_NOT_FOUND_ERROR, __FILE__, __LINE__);
124 if (S_ISDIR(buf.st_mode)) {
125 _dirList.push_back(
BESFSDir(fullPath));
128 if (_fileExpr !=
"") {
129 BESRegex reg_expr(_fileExpr.c_str());
130 int match_ret = reg_expr.
match(dirEntry.c_str(), dirEntry.length());
131 if (match_ret == static_cast<int>(dirEntry.length())) {
132 _fileList.push_back(
BESFSFile(_dirName, dirEntry));
136 _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.