From e6243d256fac39dcd217f98c43d3fac1bd32f63b Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Sun, 27 Apr 2014 09:23:17 +0200 Subject: initial commit including a network timeout for wget and curl based downloads --- src/luarocks/cfg.lua | 1 + src/luarocks/fs/unix/tools.lua | 9 ++++++++- src/luarocks/fs/win32/tools.lua | 9 ++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 1207d600..c7ca4441 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -227,6 +227,7 @@ local defaults = { lua_interpreter = site_config.LUA_INTERPRETER or "lua", downloader = site_config.LUAROCKS_DOWNLOADER or "wget", md5checker = site_config.LUAROCKS_MD5CHECKER or "md5sum", + connection_timeout = 30, -- 0 = no timeout variables = { MAKE = "make", diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index d381b8d9..7168cecc 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua @@ -247,6 +247,9 @@ function tools.download(url, filename, cache) local ok if cfg.downloader == "wget" then local wget_cmd = vars.WGET.." --no-check-certificate --no-cache --user-agent='"..cfg.user_agent.." via wget' --quiet " + if cfg.connection_timeout > 0 then + wget_cmd = wget_cmd .. "--timeout="..tonumber(cfg.connection_timeout).." " + end if cache then -- --timestamping is incompatible with --output-document, -- but that's not a problem for our use cases. @@ -259,7 +262,11 @@ function tools.download(url, filename, cache) ok = fs.execute(wget_cmd, url) end elseif cfg.downloader == "curl" then - ok = fs.execute_string(vars.CURL.." -f -L --user-agent '"..cfg.user_agent.." via curl' "..fs.Q(url).." 2> /dev/null 1> "..fs.Q(filename)) + local curl_cmd = vars.CURL.." -f -L --user-agent '"..cfg.user_agent.." via curl' " + if cfg.connection_timeout > 0 then + curl_cmd = curl_cmd .. "--connect-timeout="..tonumber(cfg.connection_timeout).." " + end + ok = fs.execute_string(curl_cmd..fs.Q(url).." 2> /dev/null 1> "..fs.Q(filename)) end if ok then return true, filename diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua index bd7ba086..df468c5d 100644 --- a/src/luarocks/fs/win32/tools.lua +++ b/src/luarocks/fs/win32/tools.lua @@ -257,6 +257,9 @@ function tools.download(url, filename, cache) local ok if cfg.downloader == "wget" then local wget_cmd = fs.Q(vars.WGET).." --no-check-certificate --no-cache --user-agent=\""..cfg.user_agent.." via wget\" --quiet " + if cfg.connection_timeout > 0 then + wget_cmd = wget_cmd .. "--timeout="..tonumber(cfg.connection_timeout).." " + end if cache then -- --timestamping is incompatible with --output-document, -- but that's not a problem for our use cases. @@ -269,7 +272,11 @@ function tools.download(url, filename, cache) ok = fs.execute(wget_cmd..fs.Q(url).." 2> NUL 1> NUL") end elseif cfg.downloader == "curl" then - ok = fs.execute_string(fs.Q(vars.CURL).." -f -L --user-agent \""..cfg.user_agent.." via curl\" "..fs.Q(url).." 2> NUL 1> "..fs.Q(filename)) + local curl_cmd = vars.CURL.." -f -L --user-agent \""..cfg.user_agent.." via curl\" " + if cfg.connection_timeout > 0 then + curl_cmd = curl_cmd .. "--connect-timeout="..tonumber(cfg.connection_timeout).." " + end + ok = fs.execute_string(curl_cmd..fs.Q(url).." 2> NUL 1> "..fs.Q(filename)) end if ok then return true, filename -- cgit v1.2.3-55-g6feb