35 #include <sys/types.h>
47 using std::ostringstream;
64 map<string, BESCatalogUtils *> BESCatalogUtils::_instances;
66 BESCatalogUtils::BESCatalogUtils(
const string &n) :
67 _name(n), _follow_syms(false) {
68 string key =
"BES.Catalog." + n +
".RootDirectory";
71 if (!found || _root_dir ==
"") {
72 string s = key +
" not defined in BES configuration file";
75 DIR *dip = opendir(_root_dir.c_str());
77 string serr =
"BESCatalogDirectory - root directory " + _root_dir
84 key = (string)
"BES.Catalog." + n +
".Exclude";
87 vector<string>::iterator ei = vals.begin();
88 vector<string>::iterator ee = vals.end();
89 for (; ei != ee; ei++) {
91 if (!e_str.empty() && e_str !=
";")
95 key = (string)
"BES.Catalog." + n +
".Include";
98 vector<string>::iterator ii = vals.begin();
99 vector<string>::iterator ie = vals.end();
100 for (; ii != ie; ii++) {
101 string i_str = (*ii);
102 if (!i_str.empty() && i_str !=
";")
106 key =
"BES.Catalog." + n +
".TypeMatch";
107 list<string> match_list;
110 if (!found || vals.size() == 0) {
111 string s = key +
" not defined in key file";
114 vector<string>::iterator vi = vals.begin();
115 vector<string>::iterator ve = vals.end();
116 for (; vi != ve; vi++) {
120 list<string>::iterator mli = match_list.begin();
121 list<string>::iterator mle = match_list.end();
122 for (; mli != mle; mli++) {
123 if (!((*mli).empty()) && *(mli) !=
";") {
126 if (amatch.size() != 2) {
127 string s = (string)
"Catalog type match malformed, "
128 +
"looking for type:regexp;[type:regexp;]";
131 list<string>::iterator ami = amatch.begin();
133 newval.
type = (*ami);
136 _match_list.push_back(newval);
140 key = (string)
"BES.Catalog." + n +
".FollowSymLinks";
144 if (s_str ==
"yes" || s_str ==
"on" || s_str ==
"true") {
150 bool toInclude =
false;
155 if (_include.size() == 0) {
158 list<string>::const_iterator i_iter = _include.begin();
159 list<string>::const_iterator i_end = _include.end();
160 for (; i_iter != i_end; i_iter++) {
161 string reg = *i_iter;
167 if (reg_expr.match(inQuestion.c_str(), inQuestion.length())
168 == static_cast<int> (inQuestion.length())) {
173 (string)
"Unable to get catalog information, "
174 +
"malformed Catalog Include parameter "
175 +
"in bes configuration file around " + reg
183 if (toInclude ==
true) {
193 list<string>::const_iterator e_iter = _exclude.begin();
194 list<string>::const_iterator e_end = _exclude.end();
195 for (; e_iter != e_end; e_iter++) {
196 string reg = *e_iter;
200 if (reg_expr.match(inQuestion.c_str(), inQuestion.length())
201 == static_cast<int> (inQuestion.length())) {
205 string serr = (string)
"Unable to get catalog information, "
206 +
"malformed Catalog Exclude parameter "
207 +
"in bes configuration file around " + reg +
": "
217 return _match_list.begin();
221 return _match_list.end();
227 unsigned int cnt = 0;
229 int statret = stat(fullnode.c_str(), &cbuf);
230 int my_errno = errno;
236 while ((dit = readdir(dip)) != NULL) {
237 string dirEntry = dit->d_name;
238 if (dirEntry !=
"." && dirEntry !=
"..") {
239 string fullPath = fullnode +
"/" + dirEntry;
246 bool continue_checking =
true;
249 int lstatret = lstat( fullPath.c_str(), &lbuf );
251 (void) lstat(fullPath.c_str(), &lbuf);
252 if (S_ISLNK( lbuf.st_mode )) {
253 continue_checking =
false;
257 if (continue_checking) {
262 statret = stat(fullPath.c_str(), &buf);
263 if (statret == 0 && S_ISDIR( buf.st_mode )) {
264 if (
exclude(dirEntry) ==
false) {
268 bes_get_stat_info(curr_entry, buf);
279 }
else if (statret == 0 && S_ISREG( buf.st_mode )) {
280 if (!dirs_only &&
include(dirEntry)) {
283 bes_get_stat_info(curr_entry, buf);
285 list<string> services;
286 isData(fullPath, _name, services);
289 bes_get_stat_info(curr_entry, buf);
299 if (my_errno == ENOENT) {
300 string error =
"Node " + use_node +
" does not exist";
301 char *s_err = strerror(my_errno);
309 string error =
"Access denied for node " + use_node;
310 char *s_err = strerror(my_errno);
312 error = error + s_err;
324 map<string, string> props;
332 props[
"name"] = name;
338 props[
"node"] =
"true";
341 props[
"count"] = strm.str();
343 props[
"node"] =
"false";
348 if (services.size()) {
349 list<string>::const_iterator si = services.begin();
350 list<string>::const_iterator se = services.end();
351 for (; si != se; si++) {
352 info->
add_tag(
"serviceRef", (*si));
358 const string &fullnode) {
360 int statret = stat(fullnode.c_str(), &cbuf);
362 bes_get_stat_info(entry, cbuf);
368 off_t sz = buf.st_size;
373 time_t mod = buf.st_mtime;
374 struct tm *stm = gmtime(&mod);
376 strftime(mdate, 64,
"%Y-%m-%d", stm);
378 strftime(mtime, 64,
"%T", stm);
390 list<string> &services) {
396 return store->
isData(inQuestion, services);
406 if (_include.size()) {
409 list<string>::const_iterator i_iter = _include.begin();
410 list<string>::const_iterator i_end = _include.end();
411 for (; i_iter != i_end; i_iter++) {
412 if (!(*i_iter).empty()) {
421 if (_exclude.size()) {
424 list<string>::const_iterator e_iter = _exclude.begin();
425 list<string>::const_iterator e_end = _exclude.end();
426 for (; e_iter != e_end; e_iter++) {
427 if (!(*e_iter).empty()) {
436 if (_match_list.size()) {
441 for (; i != ie; i++) {
465 BESCatalogUtils::_instances[cat_name] = utils;
473 map<string, BESCatalogUtils*>::iterator i = BESCatalogUtils::_instances.begin();
474 map<string, BESCatalogUtils*>::iterator e = BESCatalogUtils::_instances.end();
476 delete (*i++).second;
virtual list< string > get_service_list()
error thrown if the resource requested cannot be found
provides persistent storage for data storage information represented by a container.
BESCatalogUtils::match_citer match_list_begin() const
BESCatalogUtils::match_citer match_list_end() const
virtual string get_catalog()
exception thrown if inernal error encountered
virtual unsigned int get_count()
virtual BESContainerStorage * find_persistence(const string &persist_name)
find the persistence store with the given name
static string lowercase(const string &s)
Convert a string to all lower case.
virtual void add_tag(const string &tag_name, const string &tag_data, map< string, string > *attrs=0)=0
a C++ interface to POSIX regular expression functions.
virtual void set_mod_date(const string &mod_date)
error thrown if there is a user syntax error in the request or any other user error ...
virtual void set_service_list(list< string > &slist)
vector< type_reg >::const_iterator match_citer
virtual void set_mod_time(const string &mod_time)
virtual string get_message()
get the error message for this exception
virtual bool isData(const string &inQuestion, list< string > &provides)=0
determine if the given container is data and what services are available for it
virtual void add_entry(BESCatalogEntry *entry)
informational response object
Abstract exception class for the BES with basic string message.
static void bes_add_stat_info(BESCatalogEntry *entry, const string &fullnode)
virtual string default_catalog()
virtual string get_name()
virtual void begin_tag(const string &tag_name, map< string, string > *attrs=0)
static ostream & LMarg(ostream &strm)
bool follow_sym_links() const
static void explode(char delim, const string &str, list< string > &values)
explode a string into an array given a delimiter
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
static bool isData(const string &inQuestion, const string &catalog, list< string > &services)
virtual string get_mod_time()
static void display_entry(BESCatalogEntry *entry, BESInfo *info)
void get_value(const string &s, string &val, bool &found)
Retrieve the value of a given key, if set.
static BESContainerStorageList * TheList()
virtual void set_size(off_t size)
static void delete_all_catalogs()
virtual bool include(const string &inQuestion) const
void get_values(const string &s, vector< string > &vals, bool &found)
Retrieve the values of a given key, if set.
virtual string get_size()
virtual bool exclude(const string &inQuestion) const
static BESCatalogUtils * Utils(const string &name)
virtual unsigned int get_entries(DIR *dip, const string &fullnode, const string &use_node, const string &coi, BESCatalogEntry *entry, bool dirs_only)
virtual bool is_collection()
static BESCatalogList * TheCatalogList()
returns the singleton BESCatalogList instance.
static BESKeys * TheKeys()
virtual string get_mod_date()