From: Mikko Rasa Date: Thu, 10 May 2012 21:20:33 +0000 (+0300) Subject: Give tasks the ability to return the relevant shell command X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=64cd148dcd762ea368d9a552e982fdff83781ef2;p=builder.git Give tasks the ability to return the relevant shell command --- diff --git a/source/externaltask.cpp b/source/externaltask.cpp index 672762b..f24774e 100644 --- a/source/externaltask.cpp +++ b/source/externaltask.cpp @@ -8,11 +8,32 @@ using namespace std; using namespace Msp; -ExternalTask::ExternalTask(const vector &argv, const FS::Path &work_dir): +ExternalTask::ExternalTask(const vector &a, const FS::Path &wd): + argv(a), + work_dir(wd), pid(-1), exit_code(-1) { } +string ExternalTask::get_command() const +{ + string cmd; + for(vector::const_iterator i=argv.begin(); i!=argv.end(); ++i) + { + if(i!=argv.begin()) + cmd += ' '; + + for(string::const_iterator j=i->begin(); j!=i->end(); ++j) + { + if(*j=='"' || *j=='\'' || *j==' ' || *j=='\\' || *j=='&') + cmd += '\\'; + cmd += *j; + } + } + + return cmd; +} + void ExternalTask::start() { if((pid = fork())) diff --git a/source/externaltask.h b/source/externaltask.h index 3028e74..0bd108e 100644 --- a/source/externaltask.h +++ b/source/externaltask.h @@ -9,12 +9,15 @@ class ExternalTask: public Task { private: + std::vector argv; + Msp::FS::Path work_dir; int pid; int exit_code; public: ExternalTask(const std::vector &, const Msp::FS::Path &); + virtual std::string get_command() const; virtual void start(); virtual Status check(); }; diff --git a/source/internaltask.h b/source/internaltask.h index 9e52247..83023d3 100644 --- a/source/internaltask.h +++ b/source/internaltask.h @@ -27,6 +27,7 @@ public: InternalTask(Worker *); ~InternalTask(); + virtual std::string get_command() const { return ""; } virtual void start(); virtual Status check(); }; diff --git a/source/task.h b/source/task.h index 03d212b..531316b 100644 --- a/source/task.h +++ b/source/task.h @@ -1,6 +1,7 @@ #ifndef TASK_H_ #define TASK_H_ +#include #include class Task @@ -20,6 +21,7 @@ protected: public: virtual ~Task() { } + virtual std::string get_command() const = 0; virtual void start() = 0; virtual Status check() = 0; };