35 #include <sys/types.h> 43 using std::stringstream;
47 #include "BESCatalogDirectory.h" 48 #include "BESCatalogUtils.h" 49 #include "BESCatalogEntry.h" 51 #include "BESCatalogUtils.h" 52 #include "BESContainerStorageList.h" 53 #include "BESContainerStorageCatalog.h" 55 #include "BESForbiddenError.h" 56 #include "BESNotFoundError.h" 59 BESCatalogDirectory::BESCatalogDirectory(
const string &name) :
62 _utils = BESCatalogUtils::Utils(name);
65 BESCatalogDirectory::~BESCatalogDirectory()
70 BESCatalogDirectory::show_catalog(
const string &node,
const string &coi,
BESCatalogEntry *entry)
72 string use_node = node;
75 if (!node.empty() && node !=
"/") {
76 string::size_type pos = use_node.find_last_not_of(
"/");
77 use_node = use_node.substr(0, pos + 1);
85 string rootdir = _utils->get_root_dir();
86 string fullnode = rootdir;
87 if (!use_node.empty()) {
88 fullnode = fullnode +
"/" + use_node;
92 string::size_type slash = fullnode.rfind(
"/");
93 if (slash != string::npos) {
94 basename = fullnode.substr(slash + 1, fullnode.length() - slash);
100 BESDEBUG(
"bes",
"BESCatalogDirectory::show_catalog: " 101 <<
"use_node = " << use_node << endl
102 <<
"rootdir = " << rootdir << endl
103 <<
"fullnode = " << fullnode << endl
104 <<
"basename = " << basename << endl );
115 entry->add_entry(myentry);
123 DIR *dip = opendir(fullnode.c_str());
130 if (_utils->exclude(basename)) {
131 string error =
"You do not have permission to view the node " + use_node;
139 bool dirs_only =
false;
140 _utils->get_entries(dip, fullnode, use_node, coi, myentry, dirs_only);
147 BESCatalogUtils::bes_add_stat_info(myentry, fullnode);
152 if (_utils->include(basename)) {
155 if (_utils->follow_sym_links() ==
false) {
156 (void) lstat(fullnode.c_str(), &buf);
157 if (S_ISLNK(buf.st_mode)) {
158 string error =
"You do not have permission to access node " + use_node;
162 statret = stat(fullnode.c_str(), &buf);
163 if (statret == 0 && S_ISREG(buf.st_mode)) {
164 BESCatalogUtils::bes_add_stat_info(myentry, fullnode);
166 list < string > services;
167 BESCatalogUtils::isData(node, get_catalog_name(), services);
168 myentry->set_service_list(services);
170 else if (statret == 0) {
171 string error =
"You do not have permission to access " + use_node;
177 if (errno == ENOENT) {
178 string error =
"Node " + use_node +
" does not exist";
179 char *s_err = strerror(errno);
187 string error =
"Access denied for node " + use_node;
188 char *s_err = strerror(errno);
190 error = error + s_err;
197 string error =
"You do not have permission to access " + use_node;
214 strm << BESIndent::LMarg <<
"BESCatalogDirectory::dump - (" << (
void *)
this <<
")" << endl;
217 strm << BESIndent::LMarg <<
"catalog utilities: " << endl;
220 BESIndent::UnIndent();
221 BESIndent::UnIndent();
error thrown if the resource requested cannot be found
static void conditional_timeout_cancel()
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)