aboutsummaryrefslogtreecommitdiff
path: root/bpkg/fetch.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2017-10-17 15:02:53 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2017-10-18 05:02:40 +0300
commit3105c27bd7d42ee55c55650f83c7fc3483188b82 (patch)
treeab5db30d0b882bd147318f9c7634584f79dd3da8 /bpkg/fetch.cxx
parent1e69164d90f9882b2b90716346b363c25d1fd652 (diff)
Add support for --fetch-timeout option
Diffstat (limited to 'bpkg/fetch.cxx')
-rw-r--r--bpkg/fetch.cxx44
1 files changed, 41 insertions, 3 deletions
diff --git a/bpkg/fetch.cxx b/bpkg/fetch.cxx
index 700e345..a4f238a 100644
--- a/bpkg/fetch.cxx
+++ b/bpkg/fetch.cxx
@@ -96,6 +96,7 @@ namespace bpkg
static process
start_wget (const path& prog,
+ const optional<size_t>& timeout,
const strings& ops,
const string& url,
const path& out)
@@ -140,6 +141,15 @@ namespace bpkg
else if (verb > 3)
args.push_back ("-d");
+ // Set download timeout if requested.
+ //
+ string tm;
+ if (timeout)
+ {
+ tm = "--timeout=" + to_string (*timeout);
+ args.push_back (tm.c_str ());
+ }
+
// Add extra options. The idea if that they may override what
// we have set before this point but not after (like -O below).
//
@@ -219,6 +229,7 @@ namespace bpkg
static process
start_curl (const path& prog,
+ const optional<size_t>& timeout,
const strings& ops,
const string& url,
const path& out)
@@ -249,6 +260,16 @@ namespace bpkg
else if (verb > 3)
args.push_back ("-v");
+ // Set download timeout if requested.
+ //
+ string tm;
+ if (timeout)
+ {
+ tm = to_string (*timeout);
+ args.push_back ("--max-time");
+ args.push_back (tm.c_str ());
+ }
+
// Add extra options. The idea is that they may override what
// we have set before this point but not after.
//
@@ -334,6 +355,7 @@ namespace bpkg
static process
start_fetch (const path& prog,
+ const optional<size_t>& timeout,
const strings& ops,
const string& url,
const path& out)
@@ -358,6 +380,15 @@ namespace bpkg
else if (verb > 3)
args.push_back ("-v");
+ // Set download timeout if requested.
+ //
+ string tm;
+ if (timeout)
+ {
+ tm = "--timeout=" + to_string (*timeout);
+ args.push_back (tm.c_str ());
+ }
+
// Add extra options. The idea is that they may override what
// we have set before this point but not after (like -o below).
//
@@ -485,8 +516,11 @@ namespace bpkg
static process
start (const common_options& o, const string& url, const path& out = path ())
{
- process (*f) (
- const path&, const strings&, const string&, const path&) = nullptr;
+ process (*f) (const path&,
+ const optional<size_t>&,
+ const strings&,
+ const string&,
+ const path&) = nullptr;
switch (check (o))
{
@@ -495,9 +529,13 @@ namespace bpkg
case fetch: f = &start_fetch; break;
}
+ optional<size_t> timeout;
+ if (o.fetch_timeout_specified ())
+ timeout = o.fetch_timeout ();
+
try
{
- return f (fetch_path, o.fetch_option (), url, out);
+ return f (fetch_path, timeout, o.fetch_option (), url, out);
}
catch (const process_error& e)
{