summaryrefslogtreecommitdiffstats
path: root/src/uscxml/plugins/invoker/filesystem
diff options
context:
space:
mode:
authorStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2013-02-28 14:00:53 (GMT)
committerStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2013-02-28 14:00:53 (GMT)
commitc1ccbef7a59df33e6ff0c9a4609caab7e668ba77 (patch)
tree23d94e90f346db5d4ecff7afb6a0283fc5fe8eba /src/uscxml/plugins/invoker/filesystem
parent49c3c43d18c9cce6de305aae77cc8bd839506129 (diff)
downloaduscxml-c1ccbef7a59df33e6ff0c9a4609caab7e668ba77.zip
uscxml-c1ccbef7a59df33e6ff0c9a4609caab7e668ba77.tar.gz
uscxml-c1ccbef7a59df33e6ff0c9a4609caab7e668ba77.tar.bz2
Prepared everything for FE-Design demo
Diffstat (limited to 'src/uscxml/plugins/invoker/filesystem')
-rw-r--r--src/uscxml/plugins/invoker/filesystem/dirmon/DirMonInvoker.cpp109
-rw-r--r--src/uscxml/plugins/invoker/filesystem/dirmon/DirMonInvoker.h3
2 files changed, 79 insertions, 33 deletions
diff --git a/src/uscxml/plugins/invoker/filesystem/dirmon/DirMonInvoker.cpp b/src/uscxml/plugins/invoker/filesystem/dirmon/DirMonInvoker.cpp
index e34517d..b7477df 100644
--- a/src/uscxml/plugins/invoker/filesystem/dirmon/DirMonInvoker.cpp
+++ b/src/uscxml/plugins/invoker/filesystem/dirmon/DirMonInvoker.cpp
@@ -24,7 +24,11 @@ bool connect(pluma::Host& host) {
}
#endif
-DirMonInvoker::DirMonInvoker() : _reportExisting(false), _recurse(false), _thread(NULL) {
+DirMonInvoker::DirMonInvoker() :
+ _reportExisting(true),
+ _reportHidden(false),
+ _recurse(false),
+ _thread(NULL) {
}
DirMonInvoker::~DirMonInvoker() {
@@ -51,13 +55,31 @@ void DirMonInvoker::cancel(const std::string sendId) {
}
void DirMonInvoker::invoke(const InvokeRequest& req) {
- if (req.params.find("dir") != req.params.end() && boost::iequals(req.params.find("reportexisting")->second, "true"))
- _reportExisting = true;
+ if (req.params.find("dir") != req.params.end() && boost::iequals(req.params.find("reportexisting")->second, "false"))
+ _reportExisting = false;
if (req.params.find("recurse") != req.params.end() && boost::iequals(req.params.find("recurse")->second, "true"))
_recurse = true;
- if (req.params.find("suffix") != req.params.end())
- _suffix = req.params.find("suffix")->second;
-
+ if (req.params.find("reporthidden") != req.params.end() && boost::iequals(req.params.find("reporthidden")->second, "true"))
+ _reportHidden = true;
+
+ std::string suffixList;
+ if (req.params.find("suffix") != req.params.end()) {
+ suffixList = req.params.find("suffix")->second;
+ } else if (req.params.find("suffixes") != req.params.end()) {
+ suffixList = req.params.find("suffixes")->second;
+ }
+
+ if (suffixList.size() > 0) {
+ // seperate path into components
+ std::stringstream ss(suffixList);
+ std::string item;
+ while(std::getline(ss, item, ' ')) {
+ if (item.length() == 0)
+ continue;
+ _suffixes.insert(item);
+ }
+ }
+
std::multimap<std::string, std::string>::const_iterator dirIter = req.params.find("dir");
while(dirIter != req.params.upper_bound("dir")) {
URL url(dirIter->second);
@@ -89,14 +111,20 @@ void DirMonInvoker::reportExisting() {
}
void DirMonInvoker::handleFileAction(FW::WatchID watchid, const FW::String& dir, const FW::String& filename, FW::Action action) {
- if (!boost::algorithm::ends_with(filename, _suffix))
- return;
-
- struct stat fileStat;
- if (stat(filename.c_str(), &fileStat) != 0) {
- LOG(ERROR) << "Error with stat on directory entry " << filename << ": " << strerror(errno);
- return;
- }
+
+ if (_suffixes.size() > 0) {
+ bool validSuffix = false;
+ std::set<std::string>::iterator suffixIter = _suffixes.begin();
+ while(suffixIter != _suffixes.end()) {
+ if (boost::algorithm::ends_with(filename, *suffixIter)) {
+ validSuffix = true;
+ break;
+ }
+ suffixIter++;
+ }
+ if (!validSuffix)
+ return;
+ }
Event event;
event.invokeid = _invokeId;
@@ -117,39 +145,56 @@ void DirMonInvoker::handleFileAction(FW::WatchID watchid, const FW::String& dir,
break;
}
+ // basename is the filename with suffix
std::string basename;
size_t lastSep;
if ((lastSep = filename.find_last_of(PATH_SEPERATOR)) != std::string::npos) {
lastSep++;
basename = filename.substr(lastSep, filename.length() - lastSep);
- } else {
- basename = filename;
+ event.data.compound["file"].compound["name"] = Data(basename, Data::VERBATIM);
}
-
- std::string extension;
+
+ // return if this is a hidden file
+ if (boost::algorithm::starts_with(basename, ".") && !_reportHidden)
+ return;
+
+ struct stat fileStat;
+ if (action != FW::Actions::Delete) {
+ if (stat(filename.c_str(), &fileStat) != 0) {
+ LOG(ERROR) << "Error with stat on directory entry " << filename << ": " << strerror(errno);
+ return;
+ } else {
+ event.data.compound["file"].compound["mtime"] = toStr(fileStat.st_mtime);
+ event.data.compound["file"].compound["ctime"] = toStr(fileStat.st_ctime);
+ event.data.compound["file"].compound["atime"] = toStr(fileStat.st_atime);
+ event.data.compound["file"].compound["size"] = toStr(fileStat.st_size);
+ }
+ }
+
+ // extension is the suffix and strippedName the basename without the suffix
size_t lastDot;
if ((lastDot = basename.find_last_of(".")) != std::string::npos) {
- lastDot++;
- extension = basename.substr(lastDot, basename.length() - lastDot);
+ std::string extension = basename.substr(lastDot + 1);
+ event.data.compound["file"].compound["extension"] = Data(extension, Data::VERBATIM);
+ std::string strippedName = basename.substr(0, lastDot);
+ event.data.compound["file"].compound["strippedName"] = Data(strippedName, Data::VERBATIM);
}
- std::string relPath;
+ // relpath is the path to the file relative to the dir
if (boost::algorithm::starts_with(filename, dir)) {
- relPath = filename.substr(dir.length());
- } else {
- relPath = filename;
+ std::string relPath = filename.substr(dir.length());
+ event.data.compound["file"].compound["relPath"] = Data(relPath, Data::VERBATIM);
+
+ // relDir is the relpath without the basename
+ if ((lastSep = relPath.find_last_of(PATH_SEPERATOR)) != std::string::npos) {
+ lastSep++;
+ std::string relDir = relPath.substr(0, lastSep);
+ event.data.compound["file"].compound["relDir"] = Data(relDir, Data::VERBATIM);
+ }
}
- event.data.compound["file"].compound["name"] = Data(basename, Data::VERBATIM);
event.data.compound["file"].compound["path"] = Data(filename, Data::VERBATIM);
- event.data.compound["file"].compound["relPath"] = Data(relPath, Data::VERBATIM);
event.data.compound["file"].compound["dir"] = Data(dir, Data::VERBATIM);
- event.data.compound["file"].compound["extension"] = Data(extension, Data::VERBATIM);
-
- event.data.compound["file"].compound["mtime"] = toStr(fileStat.st_mtime);
- event.data.compound["file"].compound["ctime"] = toStr(fileStat.st_ctime);
- event.data.compound["file"].compound["atime"] = toStr(fileStat.st_atime);
- event.data.compound["file"].compound["size"] = toStr(fileStat.st_size);
returnEvent(event);
}
diff --git a/src/uscxml/plugins/invoker/filesystem/dirmon/DirMonInvoker.h b/src/uscxml/plugins/invoker/filesystem/dirmon/DirMonInvoker.h
index 1437759..04e670d 100644
--- a/src/uscxml/plugins/invoker/filesystem/dirmon/DirMonInvoker.h
+++ b/src/uscxml/plugins/invoker/filesystem/dirmon/DirMonInvoker.h
@@ -39,8 +39,9 @@ public:
protected:
bool _reportExisting;
+ bool _reportHidden;
bool _recurse;
- std::string _suffix;
+ std::set<std::string> _suffixes;
bool _isRunning;
tthread::thread* _thread;