diff options
| author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2014-04-27 09:23:17 +0200 |
|---|---|---|
| committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2014-04-27 09:23:17 +0200 |
| commit | e6243d256fac39dcd217f98c43d3fac1bd32f63b (patch) | |
| tree | 07c10c9a7b42a48bb6a8e331ad809f53c4aa6dd4 /src | |
| parent | 999e27d74abd0bc53165d2ce2642fb5a7af81f40 (diff) | |
| download | luarocks-e6243d256fac39dcd217f98c43d3fac1bd32f63b.tar.gz luarocks-e6243d256fac39dcd217f98c43d3fac1bd32f63b.tar.bz2 luarocks-e6243d256fac39dcd217f98c43d3fac1bd32f63b.zip | |
initial commit including a network timeout for wget and curl based downloads
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/cfg.lua | 1 | ||||
| -rw-r--r-- | src/luarocks/fs/unix/tools.lua | 9 | ||||
| -rw-r--r-- | 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 = { | |||
| 227 | lua_interpreter = site_config.LUA_INTERPRETER or "lua", | 227 | lua_interpreter = site_config.LUA_INTERPRETER or "lua", |
| 228 | downloader = site_config.LUAROCKS_DOWNLOADER or "wget", | 228 | downloader = site_config.LUAROCKS_DOWNLOADER or "wget", |
| 229 | md5checker = site_config.LUAROCKS_MD5CHECKER or "md5sum", | 229 | md5checker = site_config.LUAROCKS_MD5CHECKER or "md5sum", |
| 230 | connection_timeout = 30, -- 0 = no timeout | ||
| 230 | 231 | ||
| 231 | variables = { | 232 | variables = { |
| 232 | MAKE = "make", | 233 | 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) | |||
| 247 | local ok | 247 | local ok |
| 248 | if cfg.downloader == "wget" then | 248 | if cfg.downloader == "wget" then |
| 249 | local wget_cmd = vars.WGET.." --no-check-certificate --no-cache --user-agent='"..cfg.user_agent.." via wget' --quiet " | 249 | local wget_cmd = vars.WGET.." --no-check-certificate --no-cache --user-agent='"..cfg.user_agent.." via wget' --quiet " |
| 250 | if cfg.connection_timeout > 0 then | ||
| 251 | wget_cmd = wget_cmd .. "--timeout="..tonumber(cfg.connection_timeout).." " | ||
| 252 | end | ||
| 250 | if cache then | 253 | if cache then |
| 251 | -- --timestamping is incompatible with --output-document, | 254 | -- --timestamping is incompatible with --output-document, |
| 252 | -- but that's not a problem for our use cases. | 255 | -- but that's not a problem for our use cases. |
| @@ -259,7 +262,11 @@ function tools.download(url, filename, cache) | |||
| 259 | ok = fs.execute(wget_cmd, url) | 262 | ok = fs.execute(wget_cmd, url) |
| 260 | end | 263 | end |
| 261 | elseif cfg.downloader == "curl" then | 264 | elseif cfg.downloader == "curl" then |
| 262 | 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)) | 265 | local curl_cmd = vars.CURL.." -f -L --user-agent '"..cfg.user_agent.." via curl' " |
| 266 | if cfg.connection_timeout > 0 then | ||
| 267 | curl_cmd = curl_cmd .. "--connect-timeout="..tonumber(cfg.connection_timeout).." " | ||
| 268 | end | ||
| 269 | ok = fs.execute_string(curl_cmd..fs.Q(url).." 2> /dev/null 1> "..fs.Q(filename)) | ||
| 263 | end | 270 | end |
| 264 | if ok then | 271 | if ok then |
| 265 | return true, filename | 272 | 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) | |||
| 257 | local ok | 257 | local ok |
| 258 | if cfg.downloader == "wget" then | 258 | if cfg.downloader == "wget" then |
| 259 | local wget_cmd = fs.Q(vars.WGET).." --no-check-certificate --no-cache --user-agent=\""..cfg.user_agent.." via wget\" --quiet " | 259 | local wget_cmd = fs.Q(vars.WGET).." --no-check-certificate --no-cache --user-agent=\""..cfg.user_agent.." via wget\" --quiet " |
| 260 | if cfg.connection_timeout > 0 then | ||
| 261 | wget_cmd = wget_cmd .. "--timeout="..tonumber(cfg.connection_timeout).." " | ||
| 262 | end | ||
| 260 | if cache then | 263 | if cache then |
| 261 | -- --timestamping is incompatible with --output-document, | 264 | -- --timestamping is incompatible with --output-document, |
| 262 | -- but that's not a problem for our use cases. | 265 | -- but that's not a problem for our use cases. |
| @@ -269,7 +272,11 @@ function tools.download(url, filename, cache) | |||
| 269 | ok = fs.execute(wget_cmd..fs.Q(url).." 2> NUL 1> NUL") | 272 | ok = fs.execute(wget_cmd..fs.Q(url).." 2> NUL 1> NUL") |
| 270 | end | 273 | end |
| 271 | elseif cfg.downloader == "curl" then | 274 | elseif cfg.downloader == "curl" then |
| 272 | 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)) | 275 | local curl_cmd = vars.CURL.." -f -L --user-agent \""..cfg.user_agent.." via curl\" " |
| 276 | if cfg.connection_timeout > 0 then | ||
| 277 | curl_cmd = curl_cmd .. "--connect-timeout="..tonumber(cfg.connection_timeout).." " | ||
| 278 | end | ||
| 279 | ok = fs.execute_string(curl_cmd..fs.Q(url).." 2> NUL 1> "..fs.Q(filename)) | ||
| 273 | end | 280 | end |
| 274 | if ok then | 281 | if ok then |
| 275 | return true, filename | 282 | return true, filename |
