mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Merge branch '2.0.0' of tasktools.org:task into 2.0.0
This commit is contained in:
commit
c25bb6404f
7 changed files with 96 additions and 29 deletions
|
@ -72,6 +72,22 @@ Transport* Transport::getTransport(const Uri& uri)
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int Transport::execute()
|
int Transport::execute()
|
||||||
{
|
{
|
||||||
|
// quote arguments
|
||||||
|
std::vector<std::string>::iterator it = _arguments.begin ();
|
||||||
|
for (; it != _arguments.end (); it++)
|
||||||
|
{
|
||||||
|
// quote until the first appearance of '{'
|
||||||
|
size_t pos = it->find('{');
|
||||||
|
if (pos != 0)
|
||||||
|
{
|
||||||
|
// '{' is not the first character
|
||||||
|
it->insert(0, "\"");
|
||||||
|
if (pos != std::string::npos)
|
||||||
|
it->insert(pos+1, "\"");
|
||||||
|
else
|
||||||
|
it->append("\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
return ::execute(_executable, _arguments);
|
return ::execute(_executable, _arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,12 +63,12 @@ void TransportCurl::send(const std::string& source)
|
||||||
throw format (STRING_TRANSPORT_URI_NODIR, _uri._path);
|
throw format (STRING_TRANSPORT_URI_NODIR, _uri._path);
|
||||||
|
|
||||||
_arguments.push_back ("-T");
|
_arguments.push_back ("-T");
|
||||||
_arguments.push_back ("\"" + source + "\"");
|
_arguments.push_back ("\"" + escape (source, ' ') + "\"");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_arguments.push_back ("-T");
|
_arguments.push_back ("-T");
|
||||||
_arguments.push_back (source);
|
_arguments.push_back (escape (source, ' '));
|
||||||
}
|
}
|
||||||
|
|
||||||
// cmd line is: curl -T source protocol://host:port/path
|
// cmd line is: curl -T source protocol://host:port/path
|
||||||
|
@ -103,6 +103,7 @@ void TransportCurl::recv(std::string target)
|
||||||
_arguments.push_back(_uri._user);
|
_arguments.push_back(_uri._user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> targetargs;
|
||||||
|
|
||||||
if (is_filelist(_uri._path))
|
if (is_filelist(_uri._path))
|
||||||
{
|
{
|
||||||
|
@ -124,15 +125,16 @@ void TransportCurl::recv(std::string target)
|
||||||
suffix = toSplit.substr (pos+1);
|
suffix = toSplit.substr (pos+1);
|
||||||
split (splitted, toSplit.substr(0, pos), ',');
|
split (splitted, toSplit.substr(0, pos), ',');
|
||||||
|
|
||||||
target = "";
|
|
||||||
|
|
||||||
std::vector <std::string>::iterator file;
|
std::vector <std::string>::iterator file;
|
||||||
for (file = splitted.begin (); file != splitted.end (); ++file)
|
for (file = splitted.begin (); file != splitted.end (); ++file) {
|
||||||
target += " -o " + prefix + *file + suffix;
|
targetargs.push_back ("-o");
|
||||||
|
targetargs.push_back (prefix + *file + suffix);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
target = "-o " + target;
|
targetargs.push_back ("-o");
|
||||||
|
targetargs.push_back (target);
|
||||||
}
|
}
|
||||||
|
|
||||||
// cmd line is: curl protocol://host:port/path/to/source/file -o path/to/target/file
|
// cmd line is: curl protocol://host:port/path/to/source/file -o path/to/target/file
|
||||||
|
@ -145,7 +147,7 @@ void TransportCurl::recv(std::string target)
|
||||||
_arguments.push_back (_uri._protocol + "://" + _uri._host + "/" + _uri._path);
|
_arguments.push_back (_uri._protocol + "://" + _uri._host + "/" + _uri._path);
|
||||||
}
|
}
|
||||||
|
|
||||||
_arguments.push_back (target);
|
_arguments.insert (_arguments.end (), targetargs.begin (), targetargs.end ());
|
||||||
|
|
||||||
int result = execute();
|
int result = execute();
|
||||||
if (result)
|
if (result)
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include <text.h>
|
#include <text.h>
|
||||||
#include <i18n.h>
|
#include <i18n.h>
|
||||||
#include <TransportSSH.h>
|
#include <TransportSSH.h>
|
||||||
|
#include <util.h>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
TransportSSH::TransportSSH(const Uri& uri) : Transport(uri)
|
TransportSSH::TransportSSH(const Uri& uri) : Transport(uri)
|
||||||
|
@ -60,11 +61,11 @@ void TransportSSH::send(const std::string& source)
|
||||||
|
|
||||||
if (_uri._user != "")
|
if (_uri._user != "")
|
||||||
{
|
{
|
||||||
_arguments.push_back (_uri._user + "@" + _uri._host + ":" + _uri._path);
|
_arguments.push_back (_uri._user + "@" + _uri._host + ":" + escape (_uri._path, ' '));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_arguments.push_back (_uri._host + ":" + _uri._path);
|
_arguments.push_back (_uri._host + ":" + escape (_uri._path, ' '));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (execute())
|
if (execute())
|
||||||
|
@ -91,11 +92,11 @@ void TransportSSH::recv(std::string target)
|
||||||
|
|
||||||
if (_uri._user != "")
|
if (_uri._user != "")
|
||||||
{
|
{
|
||||||
_arguments.push_back (_uri._user + "@" + _uri._host + ":" + _uri._path);
|
_arguments.push_back (_uri._user + "@" + _uri._host + ":" + escape (_uri._path, ' '));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_arguments.push_back (_uri._host + ":" + _uri._path);
|
_arguments.push_back (_uri._host + ":" + escape (_uri._path, ' '));
|
||||||
}
|
}
|
||||||
|
|
||||||
_arguments.push_back (target);
|
_arguments.push_back (target);
|
||||||
|
|
16
src/Uri.cpp
16
src/Uri.cpp
|
@ -199,12 +199,18 @@ std::string Uri::ToString ()
|
||||||
return _data;
|
return _data;
|
||||||
|
|
||||||
std::string result;
|
std::string result;
|
||||||
// strip password from _user
|
|
||||||
std::string::size_type pos = _user.find (":");
|
|
||||||
result = _protocol + "://";
|
result = _protocol + "://";
|
||||||
|
|
||||||
if (_user.length () > 0)
|
if (_user.length () > 0) {
|
||||||
result += _user.substr (0, pos) + "@";
|
// obscure password in _user
|
||||||
|
std::string::size_type pos = _user.find (":");
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
std::string::size_type len = _user.length () - pos - 1;
|
||||||
|
result += _user.replace (pos+1, len, len, '*') + "@";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
result += _user + "@";
|
||||||
|
}
|
||||||
|
|
||||||
result += _host;
|
result += _host;
|
||||||
|
|
||||||
|
@ -288,7 +294,7 @@ void Uri::parse ()
|
||||||
}
|
}
|
||||||
|
|
||||||
// path is absolute for ssh:// syntax
|
// path is absolute for ssh:// syntax
|
||||||
if ( (_protocol == "ssh") && (pathDelimiter == "/") )
|
if ( (_protocol == "ssh") && (pathDelimiter == "/") && (_path[0] != '~') )
|
||||||
{
|
{
|
||||||
_path = "/" + _path;
|
_path = "/" + _path;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
#include <ViewText.h>
|
#include <ViewText.h>
|
||||||
#include <CmdShow.h>
|
#include <CmdShow.h>
|
||||||
|
#include <Uri.h>
|
||||||
|
|
||||||
extern Context context;
|
extern Context context;
|
||||||
|
|
||||||
|
@ -226,6 +227,9 @@ int CmdShow::execute (std::string& output)
|
||||||
i->substr (0, 7) != "report." &&
|
i->substr (0, 7) != "report." &&
|
||||||
i->substr (0, 6) != "alias." &&
|
i->substr (0, 6) != "alias." &&
|
||||||
i->substr (0, 5) != "hook." &&
|
i->substr (0, 5) != "hook." &&
|
||||||
|
i->substr (0, 5) != "push." &&
|
||||||
|
i->substr (0, 5) != "pull." &&
|
||||||
|
i->substr (0, 6) != "merge." &&
|
||||||
i->substr (0, 21) != "urgency.user.project." &&
|
i->substr (0, 21) != "urgency.user.project." &&
|
||||||
i->substr (0, 17) != "urgency.user.tag.")
|
i->substr (0, 17) != "urgency.user.tag.")
|
||||||
{
|
{
|
||||||
|
@ -273,9 +277,20 @@ int CmdShow::execute (std::string& output)
|
||||||
else if (std::find (default_values.begin (), default_values.end (), *i) != default_values.end ())
|
else if (std::find (default_values.begin (), default_values.end (), *i) != default_values.end ())
|
||||||
color = warning;
|
color = warning;
|
||||||
|
|
||||||
|
std::string value = context.config.get (*i);
|
||||||
|
// hide sensible information
|
||||||
|
if ( (i->substr (0, 5) == "push." ||
|
||||||
|
i->substr (0, 5) == "pull." ||
|
||||||
|
i->substr (0, 6) == "merge.") && (i->find (".uri") != std::string::npos) ) {
|
||||||
|
|
||||||
|
Uri uri (value);
|
||||||
|
uri.parse ();
|
||||||
|
value = uri.ToString ();
|
||||||
|
}
|
||||||
|
|
||||||
int row = view.addRow ();
|
int row = view.addRow ();
|
||||||
view.set (row, 0, *i, color);
|
view.set (row, 0, *i, color);
|
||||||
view.set (row, 1, context.config.get (*i), color);
|
view.set (row, 1, value, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
47
src/util.cpp
47
src/util.cpp
|
@ -405,22 +405,26 @@ int execute(const std::string& executable, std::vector<std::string> arguments)
|
||||||
if (executable == "")
|
if (executable == "")
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
// create command line before forking because the parent process also needs this for
|
||||||
|
// calling context.debug()
|
||||||
|
char shell[] = "bash";
|
||||||
|
char opt[] = "-c";
|
||||||
|
|
||||||
|
std::string cmdline = executable;
|
||||||
|
|
||||||
|
std::vector <std::string>::iterator it;
|
||||||
|
for (it = arguments.begin(); it != arguments.end(); ++it)
|
||||||
|
{
|
||||||
|
cmdline += " " + (std::string)*it;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.debug ("Executing: " + std::string(shell) + " " + std::string(opt) + " " + cmdline);
|
||||||
|
|
||||||
pid_t child_pid = fork();
|
pid_t child_pid = fork();
|
||||||
|
|
||||||
if (child_pid == 0)
|
if (child_pid == 0)
|
||||||
{
|
{
|
||||||
// this is done by the child process
|
// this is done by the child process
|
||||||
char shell[] = "bash";
|
|
||||||
char opt[] = "-c";
|
|
||||||
|
|
||||||
std::string cmdline = executable;
|
|
||||||
|
|
||||||
std::vector <std::string>::iterator it;
|
|
||||||
for (it = arguments.begin(); it != arguments.end(); ++it)
|
|
||||||
{
|
|
||||||
cmdline += " " + (std::string)*it;
|
|
||||||
}
|
|
||||||
|
|
||||||
char** argv = new char*[4];
|
char** argv = new char*[4];
|
||||||
argv[0] = shell; // bash
|
argv[0] = shell; // bash
|
||||||
argv[1] = opt; // -c
|
argv[1] = opt; // -c
|
||||||
|
@ -534,6 +538,27 @@ const std::string decode (const std::string& value)
|
||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Escapes any unescaped character of type c within the given string
|
||||||
|
// e.g. ' ' -> '\ '
|
||||||
|
const std::string escape (const std::string& value, char c)
|
||||||
|
{
|
||||||
|
std::string modified = value;
|
||||||
|
char tmp[2] = {c, '\0'};
|
||||||
|
std::string search = tmp;
|
||||||
|
std::string replace = "\\" + search;
|
||||||
|
|
||||||
|
std::string::size_type pos = modified.find (search);
|
||||||
|
while (pos != std::string::npos) {
|
||||||
|
if ( modified[pos-1] != '\\' )
|
||||||
|
modified.replace (pos, 1, replace);
|
||||||
|
|
||||||
|
pos = modified.find (search, pos+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return modified;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
|
@ -80,5 +80,7 @@ unsigned burndown_size (unsigned ntasks);
|
||||||
const std::string encode (const std::string&);
|
const std::string encode (const std::string&);
|
||||||
const std::string decode (const std::string&);
|
const std::string decode (const std::string&);
|
||||||
|
|
||||||
|
const std::string escape (const std::string&, char);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue