36 #include <boost/algorithm/string.hpp>
52 using namespace HsParser;
55 HsCommandInterpreter::HsCommandInterpreter(
Session* session)
56 : m_session(session) {
66 info = parse(line.c_str(), parser, space_p);
94 "Error: no filename supplied.");
113 "Error: no flags supplied.");
114 else if (fname ==
"")
116 "Error: no filename supplied.");
138 ::uint64_t handle = 0;
143 const char *val = value.c_str();
173 cout << valstr << endl;
192 cout << attr_val << endl;
196 ::uint64_t handle = 0;
212 cout <<
"true" << endl;
214 cout <<
"false" << endl;
220 vector<String> attrs;
226 for (vector<String>::iterator it = attrs.begin(); it != attrs.end(); ++it) {
245 cout<<
"true" << endl;
248 cout <<
"false" << endl;
255 vector<struct DirEntry> listing;
262 sort(listing.begin(), listing.end(), ascending);
263 for (
size_t ii=0; ii<listing.size(); ii++) {
264 if (listing[ii].is_dir)
268 cout << listing[ii].name << endl ;
275 vector<DirEntryAttr> listing;
283 sort(listing.begin(), listing.end(), ascending);
289 vector<DirEntryAttr> listing;
297 sort(listing.begin(), listing.end(), ascending);
312 String escaped_double_quote(
"\\\"");
313 String unescaped_double_quote(1,
'"');
314 String escaped_single_quote(
"\\\'");
315 String unescaped_single_quote(
"'");
316 String escaped_newline(
"\\n\n");
317 String unescaped_newline(1,
'\n');
319 String lock_attr(
"lock.generation");
320 String generation_attr(
"generation");
323 if (!outfile.empty()) {
325 oo =
new ofstream(state.
outfile.c_str(), ios_base::out);
330 while (!dirs.empty()) {
335 display_fname = fname;
337 vector<struct DirEntry> listing;
338 vector<String> attrs;
339 vector<String> tmp_dirs;
341 bool has_newline=
false;
346 *oo <<
"MKDIRS " << display_fname <<
";" << endl;
347 *oo <<
"OPEN " << display_fname <<
" FLAGS=READ|WRITE|CREATE ;" << endl;
350 *oo << display_fname <<
"\t" << endl;
355 for (
const auto &attr : attrs) {
356 if (attr == lock_attr || attr == generation_attr)
362 boost::algorithm::replace_all(value_str, unescaped_double_quote, escaped_double_quote);
363 boost::algorithm::replace_all(value_str, unescaped_single_quote, escaped_single_quote);
365 if (value_str.find(
"\n") != String::npos)
370 *oo <<
"ATTRSET " << display_fname <<
" " << attr <<
"=\"" << value_str <<
"\"";
376 *oo << display_fname <<
":" << attr <<
"\t" << value_str << endl;
390 for (
const auto &entry : listing) {
393 tmp_dirs.push_back(fname +
"/" + entry.name);
400 *oo <<
"OPEN " << file <<
" FLAGS=READ|WRITE|CREATE ;" << endl;
402 *oo << file <<
"\t" << endl;
407 for (
const auto &attr : attrs) {
408 if (attr == lock_attr || attr == generation_attr)
413 boost::algorithm::replace_all(value_str, unescaped_double_quote, escaped_double_quote);
414 boost::algorithm::replace_all(value_str, unescaped_single_quote, escaped_single_quote);
416 if (value_str.find(
"\n") != String::npos)
421 *oo <<
"ATTRSET " << file <<
" " << attr <<
"=\"" << value_str <<
"\"";
427 *oo << file <<
":" << attr <<
"\t" << value_str << endl;
433 for(
int ii=tmp_dirs.size()-1; ii>=0; --ii)
434 dirs.push_back(tmp_dirs[ii]);
448 cout <<
"SEQUENCER name=" << lockseq.name <<
" mode=" << lockseq.mode
449 <<
" generation=" << lockseq.generation << endl;
463 cout <<
"SEQUENCER name=" << lockseq.name <<
" mode=" << lockseq.mode
464 <<
" generation=" << lockseq.generation << endl;
466 cout <<
"busy" << endl;
468 cout <<
"Unknown status: " <<
status << endl;
490 cout <<
"SEQUENCER name=" << lockseq.
name <<
" mode=" << lockseq.
mode
491 <<
" generation=" << lockseq.
generation << endl;
503 cout << result << endl;
512 status.
get(&code, text);
516 cout <<
" - " << text;
523 code = Status::Code::CRITICAL;
525 return static_cast<int>(code);
532 for (
size_t i=0; text[i]; i++)
533 cout << text[i] << endl;
536 cout << endl <<
"no help for '" << state.
help_str <<
"'\n" << endl;
550 static const int indent_size = 2;
551 for (
size_t ii=0; ii<listing.size(); ii++) {
552 if (listing[ii].is_dir)
556 if (indent) cout <<
String(indent - indent_size,
' ') <<
"+" <<
String(indent_size - 1,
' ');
557 if (listing[ii].has_attr) {
558 String attr_val((
const char*)listing[ii].attr.base);
559 cout << listing[ii].name <<
", " << attr_name <<
"=" << attr_val << endl ;
562 cout << listing[ii].name << endl ;
Lock successfully granted.
void attr_get(uint64_t handle, const std::string &attr, DynamicBuffer &value, Timer *timer=0)
Gets an extended attribute of a file.
void readdir(uint64_t handle, std::vector< DirEntry > &listing, Timer *timer=0)
Gets a directory listing.
uint64_t open(const std::string &name, uint32_t flags, HandleCallbackPtr &callback, Timer *timer=0)
Opens a file.
void attr_list(uint64_t handle, vector< String > &anames, Timer *timer=0)
Lists all extended attributes of a file.
Holds Nagios-style program status information.
void close(uint64_t handle, Timer *timer=0)
Closes a file handle.
std::string String
A String is simply a typedef to std::string.
void lock(uint64_t handle, LockMode mode, LockSequencer *sequencerp, Timer *timer=0)
Locks a file.
The Stopwatch measures elapsed time.
int execute_line(const String &line) override
std::vector< Attribute > attrs
Exclusive lock attempt failed because another has it locked.
static const char ** get(const std::string &subject)
Po::typed_value< String > * str(String *v=0)
void readpath_attr(uint64_t handle, const std::string &attr, std::vector< DirEntryAttr > &listing, Timer *timer=0)
Gets a listing of the value of a specified atribute for each path components of the file/dir name...
uint64_t get_handle(std::string name)
int status(Status &status, Timer *timer=0)
Check the status of the Hyperspace master server.
A dynamic, resizable and reference counted memory buffer.
Code
Enumeration for status codes.
static const char * code_to_string(Code code)
uint64_t create(const std::string &name, uint32_t flags, HandleCallbackPtr &callback, const std::vector< Attribute > &init_attrs, Timer *timer=0)
Creates a file.
File system utility functions.
static void printDirEntryAttrListing(int indent, const String &attr_name, const std::vector< DirEntryAttr > listing)
A dynamic, resizable memory buffer.
void readdir_attr(uint64_t handle, const std::string &attr, bool include_sub_entries, std::vector< DirEntryAttr > &listing, Timer *timer=0)
Gets a listing of all entries in a directory which have a certain attribute .
void normalize_pathname(std::string name, std::string &normal_name)
const char * get_text(int error)
Returns a descriptive error message.
bool status(ContextPtr &context, Timer &timer, Status &status)
Runs a status check on the master.
bool exists(const std::string &name, Timer *timer=0)
Checks for the existence of a file.
void release(uint64_t handle, Timer *timer=0)
Releases any file handle locks.
void attr_set(uint64_t handle, const std::string &attr, const void *value, size_t value_len, Timer *timer=0)
Sets an extended attribute of a file.
String locate(int type)
Returns location of Hyperspace Master/Replicas.
bool attr_exists(uint64_t handle, const std::string &attr, Timer *timer=0)
Compatibility Macros for C/C++.
void attr_del(uint64_t handle, const std::string &name, Timer *timer=0)
Deletes an extended attribute of a file.
void get_sequencer(uint64_t handle, LockSequencer *sequencerp, Timer *timer=0)
Gets the lock sequencer of a locked file or directory handle.
uint32_t mode
lock mode (LOCK_MODE_SHARED or LOCK_MODE_EXCLUSIVE)
uint64_t attr_incr(uint64_t handle, const std::string &attr, Timer *timer=0)
Atomically increments the attribute and returns pre-incremented value Attribute is assumed to be a ui...
static bool expand_tilde(String &fname)
Expands a leading tilde character in a filename.
std::shared_ptr< HandleCallback > HandleCallbackPtr
void try_lock(uint64_t handle, LockMode mode, LockStatus *statusp, LockSequencer *sequencerp, Timer *timer=0)
Attempts to lock a file.
void unlink(const std::string &name, Timer *timer=0)
Removes a file or directory.
void clear()
Clears the buffer.
std::string name
Pathname of file that is locked.
#define HT_THROWF(_code_, _fmt_,...)
uint8_t * base
Pointer to the allocated memory buffer.
void get(Code *code, std::string &text) const
Gets status code and text.
size_t fill() const
Returns the size of the used portion.
This is a generic exception class for Hypertable.
void mkdir(const std::string &name, Timer *timer=0)
Creates a directory.
void mkdirs(const std::string &name, Timer *timer=0)
Creates a directory, including all intermediate paths.
Error codes, Exception handling, error logging.
#define HT_THROW(_code_, _msg_)
int code() const
Returns the error code.