From 3105c27bd7d42ee55c55650f83c7fc3483188b82 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 17 Oct 2017 15:02:53 +0300 Subject: Add support for --fetch-timeout option --- bpkg/fetch.cxx | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) (limited to 'bpkg/fetch.cxx') 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& 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& 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& 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&, + const strings&, + const string&, + const path&) = nullptr; switch (check (o)) { @@ -495,9 +529,13 @@ namespace bpkg case fetch: f = &start_fetch; break; } + optional 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) { -- cgit v1.1