aboutsummaryrefslogtreecommitdiff
path: root/bbot/utility.txx
diff options
context:
space:
mode:
Diffstat (limited to 'bbot/utility.txx')
-rw-r--r--bbot/utility.txx91
1 files changed, 75 insertions, 16 deletions
diff --git a/bbot/utility.txx b/bbot/utility.txx
index a613b11..edd674b 100644
--- a/bbot/utility.txx
+++ b/bbot/utility.txx
@@ -11,6 +11,8 @@
namespace bbot
{
+ // run_*()
+ //
template <typename I, typename O, typename E, typename P, typename... A>
process
run_io_start (tracer& t,
@@ -18,7 +20,7 @@ namespace bbot
O&& out,
E&& err,
const dir_path& cwd,
- P&& p,
+ const P& p,
A&&... args)
{
try
@@ -40,17 +42,19 @@ namespace bbot
template <typename P>
process_exit::code_type
- run_io_finish_exit (tracer&, process& pr, P&& p)
+ run_io_finish_exit (tracer&, process& pr, const P& p)
{
try
{
pr.wait ();
- if (!pr.exit->normal ())
- fail << "process " << p << " terminated abnormally: "
- << pr.exit->description ();
+ const process_exit& e (*pr.exit);
- return pr.exit->code ();
+ if (e.normal ())
+ return e.code ();
+
+ fail << "process " << p << " terminated abnormally: "
+ << e.description () << (e.core () ? " (core dumped)" : "") << endf;
}
catch (const process_error& e)
{
@@ -60,7 +64,7 @@ namespace bbot
template <typename P>
inline void
- run_io_finish (tracer& t, process& pr, P&& p)
+ run_io_finish (tracer& t, process& pr, const P& p)
{
if (run_io_finish_exit (t, pr, p) != 0)
fail << "process " << p << " terminated with non-zero exit code";
@@ -95,6 +99,47 @@ namespace bbot
run_io_finish (t, pr, p);
}
+ // curl
+ //
+ template <typename I, typename O, typename... A>
+ http_curl::
+ http_curl (tracer& t,
+ I&& in,
+ O&& out,
+ method_type m,
+ const string& url,
+ A&&... options)
+ : butl::curl ([&t] (const char* c[], size_t n) {run_trace (t, c, n);},
+ forward<I> (in),
+ forward<O> (out),
+ 2, // Diagnostics to stderr.
+ m,
+ url,
+ "-A", BBOT_USER_AGENT,
+ forward<A> (options)...)
+ {
+ }
+
+ template <typename I, typename O, typename... A>
+ tftp_curl::
+ tftp_curl (tracer& t,
+ I&& in,
+ O&& out,
+ method_type m,
+ const string& url,
+ A&&... options)
+ : butl::curl ([&t] (const char* c[], size_t n) {run_trace (t, c, n);},
+ forward<I> (in),
+ forward<O> (out),
+ 2, // Diagnostics to stderr.
+ m,
+ url,
+ forward<A> (options)...)
+ {
+ }
+
+ // *_manifest()
+ //
template <typename T>
T
parse_manifest (const path& f, const char* what, bool ignore_unknown)
@@ -107,23 +152,38 @@ namespace bbot
fail << what << " manifest file " << f << " does not exist";
ifdstream ifs (f);
- manifest_parser p (ifs, f.string ());
+ return parse_manifest<T> (ifs, f.string (), what, ignore_unknown);
+ }
+ catch (const system_error& e) // EACCES, etc.
+ {
+ fail << "unable to access " << what << " manifest " << f << ": " << e
+ << endf;
+ }
+ }
+
+ template <typename T>
+ T
+ parse_manifest (istream& is,
+ const string& name,
+ const char* what,
+ bool ignore_unknown)
+ {
+ using namespace butl;
+
+ try
+ {
+ manifest_parser p (is, name);
return T (p, ignore_unknown);
}
catch (const manifest_parsing& e)
{
fail << "invalid " << what << " manifest: "
- << f << ':' << e.line << ':' << e.column << ": " << e.description
+ << name << ':' << e.line << ':' << e.column << ": " << e.description
<< endf;
}
catch (const io_error& e)
{
- fail << "unable to read " << what << " manifest " << f << ": " << e
- << endf;
- }
- catch (const system_error& e) // EACCES, etc.
- {
- fail << "unable to access " << what << " manifest " << f << ": " << e
+ fail << "unable to read " << what << " manifest " << name << ": " << e
<< endf;
}
}
@@ -158,7 +218,6 @@ namespace bbot
const string& name,
const char* what)
{
- using namespace std;
using namespace butl;
try