35 #include <sys/types.h> 43 using std::stringstream;
46 #include "BESCatalogDirectory.h" 47 #include "BESCatalogUtils.h" 48 #include "BESCatalogEntry.h" 50 #include "BESCatalogUtils.h" 51 #include "BESContainerStorageList.h" 52 #include "BESContainerStorageCatalog.h" 54 #include "BESForbiddenError.h" 55 #include "BESNotFoundError.h" 58 BESCatalogDirectory::BESCatalogDirectory(
const string &name) :
61 _utils = BESCatalogUtils::Utils(name);
64 BESCatalogDirectory::~BESCatalogDirectory()
69 BESCatalogDirectory::show_catalog(
const string &node,
const string &coi,
BESCatalogEntry *entry)
71 string use_node = node;
74 if (!node.empty() && node !=
"/") {
75 string::size_type pos = use_node.find_last_not_of(
"/");
76 use_node = use_node.substr(0, pos + 1);
84 string rootdir = _utils->get_root_dir();
85 string fullnode = rootdir;
86 if (!use_node.empty()) {
87 fullnode = fullnode +
"/" + use_node;
91 string::size_type slash = fullnode.rfind(
"/");
92 if (slash != string::npos) {
93 basename = fullnode.substr(slash + 1, fullnode.length() - slash);
99 BESDEBUG(
"bes",
"BESCatalogDirectory::show_catalog: " 100 <<
"use_node = " << use_node << endl
101 <<
"rootdir = " << rootdir << endl
102 <<
"fullnode = " << fullnode << endl
103 <<
"basename = " << basename << endl );
114 entry->add_entry(myentry);
122 DIR *dip = opendir(fullnode.c_str());
129 if (_utils->exclude(basename)) {
130 string error =
"You do not have permission to view the node " + use_node;
134 bool dirs_only =
false;
135 _utils->get_entries(dip, fullnode, use_node, coi, myentry, dirs_only);
142 BESCatalogUtils::bes_add_stat_info(myentry, fullnode);
147 if (_utils->include(basename)) {
150 if (_utils->follow_sym_links() ==
false) {
151 (void) lstat(fullnode.c_str(), &buf);
152 if (S_ISLNK(buf.st_mode)) {
153 string error =
"You do not have permission to access node " + use_node;
157 statret = stat(fullnode.c_str(), &buf);
158 if (statret == 0 && S_ISREG(buf.st_mode)) {
159 BESCatalogUtils::bes_add_stat_info(myentry, fullnode);
161 list < string > services;
162 BESCatalogUtils::isData(node, get_catalog_name(), services);
163 myentry->set_service_list(services);
165 else if (statret == 0) {
166 string error =
"You do not have permission to access " + use_node;
172 if (errno == ENOENT) {
173 string error =
"Node " + use_node +
" does not exist";
174 char *s_err = strerror(errno);
182 string error =
"Access denied for node " + use_node;
183 char *s_err = strerror(errno);
185 error = error + s_err;
192 string error =
"You do not have permission to access " + use_node;
209 strm << BESIndent::LMarg <<
"BESCatalogDirectory::dump - (" << (
void *)
this <<
")" << endl;
212 strm << BESIndent::LMarg <<
"catalog utilities: " << endl;
215 BESIndent::UnIndent();
216 BESIndent::UnIndent();
error thrown if the resource requested cannot be found
virtual void dump(ostream &strm) const
dumps information about this object
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
abstract base class catalog object. Derived classes know how to show nodes and leaves in a catalog...
error thrown if the BES is not allowed to access the resource requested
static void check_path(const string &path, const string &root, bool follow_sym_links)