13 namespace SWC {
namespace Utils {
namespace shell {
16 :
Interface(
"\033[32mSWC-DB(\033[36mfs-" +
17 Env::Config::settings()->get_str(
"swc.fs") +
18 "\033[32m)\033[33m> \033[00m",
20 Env::Config::settings()->get_str(
"swc.fs") +
"-history",
30 {
"list directory contents",
32 [ptr=
this](
const std::string& cmd){
return ptr->ls(cmd); },
39 #if defined(SWC_ENABLE_SANITIZER)
40 std::this_thread::sleep_for(std::chrono::seconds(2));
45 bool Fs::ls(
const std::string& cmd) {
48 RE2::FullMatch(cmd,
"(?i)^(ls|list)\\s+(.*)$",
nullptr, &path);
49 if(path.front() ==
'"' || path.front() ==
'\'')
50 path = path.substr(1, path.size()-2);
56 return error(
"Problem reading '"+path+
"'");
63 for(
auto& entry : entries) {
64 if(entry.name.size() > lname)
65 lname = entry.name.size();
67 auto& tmp = entry.is_dir ? dirs : files;
68 for(
auto it = tmp.cbegin(); ; ++it) {
69 if(it == tmp.cend() ||
71 reinterpret_cast<const uint8_t*
>((*it)->name.c_str()),
73 reinterpret_cast<const uint8_t*
>(entry.name.c_str()),
74 entry.name.size() ) ) {
85 for(
auto& entry : dirs) {
86 t_secs = entry->last_modification_time;
87 std::strftime(modified, 20,
"%Y/%m/%d %H:%M:%S", std::gmtime(&t_secs));
90 << std::left << std::setw(lname + 2)
91 <<
format(
"'%s'", entry->name.c_str())
92 << std::left <<
" modified=" << modified
97 for(
auto& entry : files) {
98 t_secs = entry->last_modification_time;
99 std::strftime(modified, 20,
"%Y/%m/%d %H:%M:%S", std::gmtime(&t_secs));
102 << std::left << std::setw(lname + 2)
103 <<
format(
"'%s'", entry->name.c_str())
104 << std::left <<
" modified=" << modified
105 <<
" size=" << entry->length