diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2014-05-03 16:53:41 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2014-05-03 16:59:56 -0300 |
commit | 4396b504b7848081322cbaa9d5e26c9641a161b4 (patch) | |
tree | c05f11dde91304016206f93a4d07f0c01c632671 | |
parent | dca17835db0ed60f971acf33a0c78d203bc5e22f (diff) | |
download | luarocks-4396b504b7848081322cbaa9d5e26c9641a161b4.tar.gz luarocks-4396b504b7848081322cbaa9d5e26c9641a161b4.tar.bz2 luarocks-4396b504b7848081322cbaa9d5e26c9641a161b4.zip |
Set timeout in LuaSocket/LuaSec based implementation as well.
Be more forgiving with thi cfg.connection_timeout setting.
Add --timeout flag, as discussed in #249.
-rw-r--r-- | src/luarocks/command_line.lua | 9 | ||||
-rw-r--r-- | src/luarocks/fs/lua.lua | 3 | ||||
-rw-r--r-- | src/luarocks/fs/unix/tools.lua | 4 | ||||
-rw-r--r-- | src/luarocks/fs/win32/tools.lua | 4 | ||||
-rw-r--r-- | src/luarocks/help.lua | 5 |
5 files changed, 20 insertions, 5 deletions
diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index 3cde4c41..cc2e1683 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua | |||
@@ -83,6 +83,15 @@ function command_line.run_command(...) | |||
83 | fs.verbose() | 83 | fs.verbose() |
84 | end | 84 | end |
85 | 85 | ||
86 | if flags["timeout"] then -- setting it in the config file will kick-in earlier in the process | ||
87 | local timeout = tonumber(flags["timeout"]) | ||
88 | if timeout then | ||
89 | cfg.connection_timeout = timeout | ||
90 | else | ||
91 | die "Argument error: --timeout expects a numeric argument." | ||
92 | end | ||
93 | end | ||
94 | |||
86 | if flags["version"] then | 95 | if flags["version"] then |
87 | util.printout(program.." "..cfg.program_version) | 96 | util.printout(program.." "..cfg.program_version) |
88 | util.printout(program_description) | 97 | util.printout(program_description) |
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index cd705eef..f18deac3 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
@@ -551,6 +551,9 @@ local function request(url, method, http, loop_control) | |||
551 | io.write(method.." "..url.." ...\n") | 551 | io.write(method.." "..url.." ...\n") |
552 | end | 552 | end |
553 | local dots = 0 | 553 | local dots = 0 |
554 | if cfg.connection_timeout and cfg.connection_timeout > 0 then | ||
555 | http.TIMEOUT = cfg.connection_timeout | ||
556 | end | ||
554 | local res, status, headers, err = http.request { | 557 | local res, status, headers, err = http.request { |
555 | url = url, | 558 | url = url, |
556 | proxy = proxy, | 559 | proxy = proxy, |
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index 88189e07..f8f39eca 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua | |||
@@ -247,7 +247,7 @@ 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 = fs.Q(vars.WGET).." --no-check-certificate --no-cache --user-agent='"..cfg.user_agent.." via wget' --quiet " | 249 | local wget_cmd = fs.Q(vars.WGET).." --no-check-certificate --no-cache --user-agent='"..cfg.user_agent.." via wget' --quiet " |
250 | if cfg.connection_timeout > 0 then | 250 | if cfg.connection_timeout and cfg.connection_timeout > 0 then |
251 | wget_cmd = wget_cmd .. "--timeout="..tonumber(cfg.connection_timeout).." --tries=1 " | 251 | wget_cmd = wget_cmd .. "--timeout="..tonumber(cfg.connection_timeout).." --tries=1 " |
252 | end | 252 | end |
253 | if cache then | 253 | if cache then |
@@ -263,7 +263,7 @@ function tools.download(url, filename, cache) | |||
263 | end | 263 | end |
264 | elseif cfg.downloader == "curl" then | 264 | elseif cfg.downloader == "curl" then |
265 | local curl_cmd = fs.Q(vars.CURL).." -f -k -L --user-agent '"..cfg.user_agent.." via curl' " | 265 | local curl_cmd = fs.Q(vars.CURL).." -f -k -L --user-agent '"..cfg.user_agent.." via curl' " |
266 | if cfg.connection_timeout > 0 then | 266 | if cfg.connection_timeout and cfg.connection_timeout > 0 then |
267 | curl_cmd = curl_cmd .. "--connect-timeout="..tonumber(cfg.connection_timeout).." " | 267 | curl_cmd = curl_cmd .. "--connect-timeout="..tonumber(cfg.connection_timeout).." " |
268 | end | 268 | end |
269 | ok = fs.execute_string(curl_cmd..fs.Q(url).." 2> /dev/null 1> "..fs.Q(filename)) | 269 | ok = fs.execute_string(curl_cmd..fs.Q(url).." 2> /dev/null 1> "..fs.Q(filename)) |
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua index 9f32bf5b..21d846b9 100644 --- a/src/luarocks/fs/win32/tools.lua +++ b/src/luarocks/fs/win32/tools.lua | |||
@@ -257,7 +257,7 @@ 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 | 260 | if cfg.connection_timeout and cfg.connection_timeout > 0 then |
261 | wget_cmd = wget_cmd .. "--timeout="..tonumber(cfg.connection_timeout).." --tries=1 " | 261 | wget_cmd = wget_cmd .. "--timeout="..tonumber(cfg.connection_timeout).." --tries=1 " |
262 | end | 262 | end |
263 | if cache then | 263 | if cache then |
@@ -273,7 +273,7 @@ function tools.download(url, filename, cache) | |||
273 | end | 273 | end |
274 | elseif cfg.downloader == "curl" then | 274 | elseif cfg.downloader == "curl" then |
275 | local curl_cmd = vars.CURL.." -f -k -L --user-agent \""..cfg.user_agent.." via curl\" " | 275 | local curl_cmd = vars.CURL.." -f -k -L --user-agent \""..cfg.user_agent.." via curl\" " |
276 | if cfg.connection_timeout > 0 then | 276 | if cfg.connection_timeout and cfg.connection_timeout > 0 then |
277 | curl_cmd = curl_cmd .. "--connect-timeout="..tonumber(cfg.connection_timeout).." " | 277 | curl_cmd = curl_cmd .. "--connect-timeout="..tonumber(cfg.connection_timeout).." " |
278 | end | 278 | end |
279 | ok = fs.execute_string(curl_cmd..fs.Q(url).." 2> NUL 1> "..fs.Q(filename)) | 279 | ok = fs.execute_string(curl_cmd..fs.Q(url).." 2> NUL 1> "..fs.Q(filename)) |
diff --git a/src/luarocks/help.lua b/src/luarocks/help.lua index 3e428a4a..0a155509 100644 --- a/src/luarocks/help.lua +++ b/src/luarocks/help.lua | |||
@@ -66,7 +66,10 @@ function help.run(...) | |||
66 | --tree=<tree> Which tree to operate on. | 66 | --tree=<tree> Which tree to operate on. |
67 | --local Use the tree in the user's home directory. | 67 | --local Use the tree in the user's home directory. |
68 | To enable it, see ']]..program..[[ help path'. | 68 | To enable it, see ']]..program..[[ help path'. |
69 | --verbose Display verbose output of commands executed.]]) | 69 | --verbose Display verbose output of commands executed. |
70 | --timeout=<seconds> Timeout on network operations, in seconds. | ||
71 | 0 means no timeout (wait forever). | ||
72 | Default is ]]..cfg.connection_timeout..[[.]]) | ||
70 | print_section("VARIABLES") | 73 | print_section("VARIABLES") |
71 | util.printout([[ | 74 | util.printout([[ |
72 | Variables from the "variables" table of the configuration file | 75 | Variables from the "variables" table of the configuration file |