35 #include <sys/types.h> 43 using std::stringstream ;
60 const string &node ) ;
84 string use_node = node ;
87 string::size_type stopat = node.length() - 1 ;
88 while( node[stopat] ==
'/' )
92 use_node = use_node.substr( 0, stopat + 1 ) ;
95 string use_node = node;
98 if (!node.empty() && node !=
"/") {
99 string::size_type pos = use_node.find_last_not_of(
"/");
100 use_node = use_node.substr(0, pos+1);
105 if (use_node.empty())
108 BESDEBUG(
"bes",
"use_node: " << use_node << endl ) ;
111 string fullnode = rootdir ;
112 if( !use_node.empty() )
114 fullnode = fullnode +
"/" + use_node ;
118 string::size_type slash = fullnode.rfind(
"/" ) ;
119 if( slash != string::npos )
121 basename = fullnode.substr( slash+1, fullnode.length() - slash ) ;
125 basename = fullnode ;
135 DIR *dip = opendir( fullnode.c_str() ) ;
142 if( _utils->
exclude( basename ) )
145 string error =
"You do not have permission to view the node " 150 int statret = stat( fullnode.c_str(), &cbuf ) ;
151 int my_errno = errno ;
154 map<string,string> props ;
155 props[
"node"] =
"true" ;
167 unsigned int cnt = 0 ;
171 map<string,bes_dir_entry> dir_list ;
172 while( ( dit = readdir( dip ) ) != NULL )
174 string dirEntry = dit->d_name ;
175 if( dirEntry !=
"." && dirEntry !=
".." )
177 string fullPath = fullnode +
"/" + dirEntry ;
184 bool continue_checking = true ;
188 int lstatret = lstat( fullPath.c_str(), &lbuf ) ;
190 (void)lstat( fullPath.c_str(), &lbuf ) ;
191 if( S_ISLNK( lbuf.st_mode ) )
193 continue_checking = false ;
197 if( continue_checking )
203 statret = stat( fullPath.c_str(), &buf ) ;
204 if ( statret == 0 && S_ISDIR( buf.st_mode ) )
206 if( _utils->
exclude( dirEntry ) == false )
214 dir_list[dirEntry] = entry ;
218 else if ( statret == 0 && S_ISREG( buf.st_mode ) )
220 if( _utils->
include( dirEntry ) )
227 isData( fullPath, entry.
services ) ;
229 dir_list[dirEntry] = entry ;
238 props[
"count"] = sscnt.str() ;
245 map<string,bes_dir_entry>::iterator i = dir_list.begin() ;
246 map<string,bes_dir_entry>::iterator e = dir_list.end() ;
249 map<string,string> attrs ;
250 if( (*i).second.collection )
251 attrs[
"node"] =
"true" ;
253 attrs[
"node"] =
"false" ;
255 attrs[
"name"] = (*i).second.name ;
256 attrs[
"size"] = (*i).second.size ;
257 string dt = (*i).second.mod_date +
"T" 258 + (*i).second.mod_time ;
259 attrs[
"lastModified"] = dt ;
262 list<string>::const_iterator si =
263 (*i).second.services.begin() ;
264 list<string>::const_iterator se =
265 (*i).second.services.end() ;
266 for( ; si != se; si++ )
268 info->
add_tag(
"serviceRef", (*si) ) ;
280 if( my_errno == ENOENT )
282 string error =
"Node " + use_node +
" does not exist" ;
283 char *s_err = strerror( my_errno ) ;
293 string error =
"Access denied for node " + use_node ;
294 char *s_err = strerror( my_errno ) ;
297 error = error + s_err ;
307 if( _utils->
include( basename ) )
313 (void)lstat( fullnode.c_str(), &buf ) ;
314 if( S_ISLNK( buf.st_mode ) )
316 string error =
"You do not have permission to access node " 321 statret = stat( fullnode.c_str(), &buf ) ;
322 if ( statret == 0 && S_ISREG( buf.st_mode ) )
324 map<string,string> attrs ;
325 attrs[
"node"] =
"false" ;
330 list<string> services ;
331 isData( node, services ) ;
332 list<string>::const_iterator si = services.begin() ;
333 list<string>::const_iterator se = services.end() ;
334 for( ; si != se; si++ )
336 info->
add_tag(
"serviceRef", (*si) ) ;
341 else if( statret == 0 )
343 string error =
"You do not have permission to access " 351 if( errno == ENOENT )
353 string error =
"Node " + use_node +
" does not exist" ;
354 char *s_err = strerror( errno ) ;
364 string error =
"Access denied for node " + use_node ;
365 char *s_err = strerror( errno ) ;
368 error = error + s_err ;
376 string error =
"You do not have permission to access " + use_node ;
389 props[
"name"] = entry.
name ;
390 props[
"size"] = entry.
size ;
392 props[
"lastModified"] = dt ;
397 struct stat &buf,
const string &node )
401 off_t sz = buf.st_size ;
404 entry.
size = ssz.str() ;
408 time_t mod = buf.st_mtime ;
409 struct tm *stm = gmtime( &mod ) ;
411 strftime( mdate, 64,
"%Y-%m-%d", stm ) ;
413 strftime( mtime, 64,
"%T", stm ) ;
425 BESCatalogDirectory::isData(
const string &inQuestion,
426 list<string> &services )
438 return cat_store->
isData( inQuestion, services ) ;
452 << (
void *)
this <<
")" << endl ;
457 _utils->
dump( strm ) ;
error thrown if the resource requested cannot be found
provides persistent storage for data storage information represented by a container.
static const BESCatalogUtils * Utils(const string &name)
virtual BESContainerStorage * find_persistence(const string &persist_name)
find the persistence store with the given name
virtual void add_tag(const string &tag_name, const string &tag_data, map< string, string > *attrs=0)=0
virtual void dump(ostream &strm) const
dumps information about this object
implementation of BESContainerStorage that represents a data within a catalog repository ...
bool isData(const string &inQuestion, list< string > &provides)
is the specified node in question served by a request handler
informational response object
const string & get_root_dir() const
BESCatalogDirectory(const string &name)
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
virtual void begin_tag(const string &tag_name, map< string, string > *attrs=0)
static ostream & LMarg(ostream &strm)
virtual bool include(const string &inQuestion) const
abstract base class catalog object.
error thrown if the BES is not allowed to access the resource requested
virtual bool exclude(const string &inQuestion) const
static BESContainerStorageList * TheList()
void bes_get_stat_info(BESCatalogDirectory::bes_dir_entry &entry, struct stat &buf, const string &node)
virtual ~BESCatalogDirectory(void)
virtual string get_catalog_name()
void bes_add_stat_info(map< string, string > &props, struct stat &buf, const string &node)
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
static void check_path(const string &path, const string &root, bool follow_sym_links)
Check if the specified path is valid.
virtual void end_tag(const string &tag_name)
bool follow_sym_links() const
virtual void show_catalog(const string &container, const string &catalog_or_info, BESInfo *info)