35 #include <sys/types.h>
51 map<string, BESCatalogUtils *> BESCatalogUtils::_instances ;
54 BESCatalogUtils(
const string &n )
55 : _follow_syms( false )
57 string key =
"BES.Catalog." + n +
".RootDirectory" ;
60 if( !found || _root_dir ==
"" )
62 string s = key +
" not defined in BES configuration file" ;
65 DIR *dip = opendir( _root_dir.c_str() ) ;
68 string serr =
"BESCatalogDirectory - root directory "
69 + _root_dir +
" does not exist" ;
75 key = (string)
"BES.Catalog." + n +
".Exclude" ;
78 vector<string>::iterator ei = vals.begin() ;
79 vector<string>::iterator ee = vals.end() ;
80 for( ; ei != ee; ei++ )
82 string e_str = (*ei) ;
83 if( !e_str.empty() && e_str !=
";" )
87 key = (string)
"BES.Catalog." + n +
".Include" ;
90 vector<string>::iterator ii = vals.begin() ;
91 vector<string>::iterator ie = vals.end() ;
92 for( ; ii != ie; ii++ )
94 string i_str = (*ii) ;
95 if( !i_str.empty() && i_str !=
";" )
99 key =
"BES.Catalog." + n +
".TypeMatch" ;
100 list<string> match_list ;
103 if( !found || vals.size() == 0 )
105 string s = key +
" not defined in key file" ;
108 vector<string>::iterator vi = vals.begin() ;
109 vector<string>::iterator ve = vals.end() ;
110 for( ; vi != ve; vi++ )
115 list<string>::iterator mli = match_list.begin() ;
116 list<string>::iterator mle = match_list.end() ;
117 for( ; mli != mle; mli++ )
119 if( !((*mli).empty()) && *(mli) !=
";" )
121 list<string> amatch ;
123 if( amatch.size() != 2 )
125 string s = (string)
"Catalog type match malformed, "
126 +
"looking for type:regexp;[type:regexp;]" ;
129 list<string>::iterator ami = amatch.begin() ;
131 newval.
type = (*ami) ;
133 newval.
reg = (*ami) ;
134 _match_list.push_back( newval ) ;
138 key = (string)
"BES.Catalog." + n +
".FollowSymLinks" ;
142 if( s_str ==
"yes" || s_str ==
"on" || s_str ==
"true" )
144 _follow_syms = true ;
151 bool toInclude = false ;
156 if( _include.size() == 0 )
162 list<string>::const_iterator i_iter = _include.begin() ;
163 list<string>::const_iterator i_end = _include.end() ;
164 for( ; i_iter != i_end; i_iter++ )
166 string reg = *i_iter ;
174 if( reg_expr.match( inQuestion.c_str(),
175 inQuestion.length() ) ==
176 static_cast<int>(inQuestion.length()) )
183 string serr = (string)
"Unable to get catalog information, "
184 +
"malformed Catalog Include parameter "
185 +
"in bes configuration file around "
193 if( toInclude ==
true )
207 list<string>::const_iterator e_iter = _exclude.begin() ;
208 list<string>::const_iterator e_end = _exclude.end() ;
209 for( ; e_iter != e_end; e_iter++ )
211 string reg = *e_iter ;
217 if( reg_expr.match( inQuestion.c_str(), inQuestion.length() ) ==
218 static_cast<int>(inQuestion.length()) )
225 string serr = (string)
"Unable to get catalog information, "
226 +
"malformed Catalog Exclude parameter "
227 +
"in bes configuration file around "
239 return _match_list.begin() ;
245 return _match_list.end() ;
252 << (
void *)
this <<
")" << endl ;
257 if( _include.size() )
261 list<string>::const_iterator i_iter = _include.begin() ;
262 list<string>::const_iterator i_end = _include.end() ;
263 for( ; i_iter != i_end; i_iter++ )
265 if( !(*i_iter).empty() )
277 if( _exclude.size() )
281 list<string>::const_iterator e_iter = _exclude.begin() ;
282 list<string>::const_iterator e_end = _exclude.end() ;
283 for( ; e_iter != e_end; e_iter++ )
285 if( !(*e_iter).empty() )
297 if( _match_list.size() )
303 for( ; i != ie; i++ )
307 << match.
reg << endl ;
335 BESCatalogUtils::_instances[cat_name] = utils ;