diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2020-02-20 15:18:29 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-20 15:18:29 -0300 |
commit | 568624c42d3ce2e0781e644e881f4b696424829f (patch) | |
tree | d5f18e3f71adfa03829dd8eb85841580a63ddd04 | |
parent | dbd8c0dcdc50f4b79ce616221c43de03356e8264 (diff) | |
download | luarocks-568624c42d3ce2e0781e644e881f4b696424829f.tar.gz luarocks-568624c42d3ce2e0781e644e881f4b696424829f.tar.bz2 luarocks-568624c42d3ce2e0781e644e881f4b696424829f.zip |
fs: always check for failure of fs.which_tool (#1157)
-rw-r--r-- | spec/install_spec.lua | 12 | ||||
-rw-r--r-- | spec/util/test_env.lua | 6 | ||||
-rw-r--r-- | src/luarocks/fetch.lua | 4 | ||||
-rw-r--r-- | src/luarocks/fs/lua.lua | 5 | ||||
-rw-r--r-- | src/luarocks/fs/tools.lua | 44 |
5 files changed, 48 insertions, 23 deletions
diff --git a/spec/install_spec.lua b/spec/install_spec.lua index 5ee913f0..78b4b28d 100644 --- a/spec/install_spec.lua +++ b/spec/install_spec.lua | |||
@@ -56,6 +56,18 @@ describe("luarocks install #integration", function() | |||
56 | assert.is_false(run.luarocks_bool("install --local luasocket ", { USER = "root" } )) | 56 | assert.is_false(run.luarocks_bool("install --local luasocket ", { USER = "root" } )) |
57 | end) | 57 | end) |
58 | 58 | ||
59 | it("fails with no downloader", function() | ||
60 | if test_env.TYPE_TEST_ENV ~= "full" then | ||
61 | local output = assert(run.luarocks("install https://example.com/rock-1.0.src.rock", { LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/testing_config_no_downloader.lua" } )) | ||
62 | assert.match("no downloader tool", output) | ||
63 | |||
64 | -- can do http but not https | ||
65 | assert(run.luarocks("install luasocket")) | ||
66 | output = assert(run.luarocks("install https://example.com/rock-1.0.src.rock", { LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/testing_config_no_downloader.lua" } )) | ||
67 | assert.match("no downloader tool", output) | ||
68 | end | ||
69 | end) | ||
70 | |||
59 | it("fails not a zip file", function() | 71 | it("fails not a zip file", function() |
60 | test_env.run_in_tmp(function(tmpdir) | 72 | test_env.run_in_tmp(function(tmpdir) |
61 | write_file("not_a_zipfile-1.0-1.src.rock", [[ | 73 | write_file("not_a_zipfile-1.0-1.src.rock", [[ |
diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua index d4591c91..8aebd74e 100644 --- a/spec/util/test_env.lua +++ b/spec/util/test_env.lua | |||
@@ -709,7 +709,9 @@ end | |||
709 | --- Create configs for luacov and several versions of Luarocks | 709 | --- Create configs for luacov and several versions of Luarocks |
710 | -- configs needed for some tests. | 710 | -- configs needed for some tests. |
711 | local function create_configs() | 711 | local function create_configs() |
712 | -- testing_config.lua and testing_config_show_downloads.lua | 712 | -- testing_config.lua |
713 | -- testing_config_show_downloads.lua | ||
714 | -- testing_config_no_downloader.lua | ||
713 | local config_content = substitute([[ | 715 | local config_content = substitute([[ |
714 | rocks_trees = { | 716 | rocks_trees = { |
715 | "%{testing_tree}", | 717 | "%{testing_tree}", |
@@ -737,6 +739,8 @@ local function create_configs() | |||
737 | test_env.write_file(test_env.testing_paths.testrun_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"") | 739 | test_env.write_file(test_env.testing_paths.testrun_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"") |
738 | test_env.write_file(test_env.testing_paths.testrun_dir .. "/testing_config_show_downloads.lua", config_content | 740 | test_env.write_file(test_env.testing_paths.testrun_dir .. "/testing_config_show_downloads.lua", config_content |
739 | .. "show_downloads = true \n rocks_servers={\"http://luarocks.org/repositories/rocks\"}") | 741 | .. "show_downloads = true \n rocks_servers={\"http://luarocks.org/repositories/rocks\"}") |
742 | test_env.write_file(test_env.testing_paths.testrun_dir .. "/testing_config_no_downloader.lua", config_content | ||
743 | .. "variables = { WGET = 'invalid', CURL = 'invalid' }") | ||
740 | 744 | ||
741 | -- testing_config_sftp.lua | 745 | -- testing_config_sftp.lua |
742 | config_content = substitute([[ | 746 | config_content = substitute([[ |
diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index 464061d1..da912d3e 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua | |||
@@ -31,7 +31,7 @@ function fetch.fetch_caching(url) | |||
31 | 31 | ||
32 | local file, err, errcode, from_cache = fetch.fetch_url(url, cachefile, true) | 32 | local file, err, errcode, from_cache = fetch.fetch_url(url, cachefile, true) |
33 | if not file then | 33 | if not file then |
34 | return nil, "Failed downloading "..repo_url..(err and " - "..err or ""), errcode | 34 | return nil, err or "Failed downloading "..url, errcode |
35 | end | 35 | end |
36 | return file, nil, nil, from_cache | 36 | return file, nil, nil, from_cache |
37 | end | 37 | end |
@@ -67,7 +67,7 @@ function fetch.fetch_url(url, filename, cache) | |||
67 | elseif dir.is_basic_protocol(protocol) then | 67 | elseif dir.is_basic_protocol(protocol) then |
68 | local ok, name, from_cache = fs.download(url, filename, cache) | 68 | local ok, name, from_cache = fs.download(url, filename, cache) |
69 | if not ok then | 69 | if not ok then |
70 | return nil, "Failed downloading "..url..(filename and " - "..filename or ""), "network" | 70 | return nil, "Failed downloading "..url..(name and " - "..name or ""), "network" |
71 | end | 71 | end |
72 | return name, nil, nil, from_cache | 72 | return name, nil, nil, from_cache |
73 | else | 73 | else |
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index c5cebd2f..b6314a44 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
@@ -905,8 +905,11 @@ function fs_lua.download(url, filename, cache) | |||
905 | err = "Unsupported protocol" | 905 | err = "Unsupported protocol" |
906 | end | 906 | end |
907 | if https_err then | 907 | if https_err then |
908 | local downloader, err = fs.which_tool("downloader") | ||
909 | if not downloader then | ||
910 | return nil, err | ||
911 | end | ||
908 | if not downloader_warning then | 912 | if not downloader_warning then |
909 | local downloader = fs.which_tool("downloader") | ||
910 | util.warning("falling back to "..downloader.." - install luasec to get native HTTPS support") | 913 | util.warning("falling back to "..downloader.." - install luasec to get native HTTPS support") |
911 | downloader_warning = true | 914 | downloader_warning = true |
912 | end | 915 | end |
diff --git a/src/luarocks/fs/tools.lua b/src/luarocks/fs/tools.lua index 541352c2..fdb93dba 100644 --- a/src/luarocks/fs/tools.lua +++ b/src/luarocks/fs/tools.lua | |||
@@ -15,10 +15,12 @@ do | |||
15 | 15 | ||
16 | local tool_options = { | 16 | local tool_options = { |
17 | downloader = { | 17 | downloader = { |
18 | desc = "downloader", | ||
18 | { var = "WGET", name = "wget" }, | 19 | { var = "WGET", name = "wget" }, |
19 | { var = "CURL", name = "curl" }, | 20 | { var = "CURL", name = "curl" }, |
20 | }, | 21 | }, |
21 | md5checker = { | 22 | md5checker = { |
23 | desc = "MD5 checker", | ||
22 | { var = "MD5SUM", name = "md5sum" }, | 24 | { var = "MD5SUM", name = "md5sum" }, |
23 | { var = "OPENSSL", name = "openssl", cmdarg = "md5", checkarg = "version" }, | 25 | { var = "OPENSSL", name = "openssl", cmdarg = "md5", checkarg = "version" }, |
24 | { var = "MD5", name = "md5", checkarg = "-shello" }, | 26 | { var = "MD5", name = "md5", checkarg = "-shello" }, |
@@ -27,8 +29,10 @@ do | |||
27 | 29 | ||
28 | function tools.which_tool(tooltype) | 30 | function tools.which_tool(tooltype) |
29 | local tool = tool_cache[tooltype] | 31 | local tool = tool_cache[tooltype] |
32 | local names = {} | ||
30 | if not tool then | 33 | if not tool then |
31 | for _, opt in ipairs(tool_options[tooltype]) do | 34 | for _, opt in ipairs(tool_options[tooltype]) do |
35 | table.insert(names, opt.name) | ||
32 | if fs.is_tool_available(vars[opt.var], opt.name, opt.checkarg) then | 36 | if fs.is_tool_available(vars[opt.var], opt.name, opt.checkarg) then |
33 | tool = opt | 37 | tool = opt |
34 | tool_cache[tooltype] = opt | 38 | tool_cache[tooltype] = opt |
@@ -37,7 +41,8 @@ do | |||
37 | end | 41 | end |
38 | end | 42 | end |
39 | if not tool then | 43 | if not tool then |
40 | return nil | 44 | local tool_names = table.concat(names, ", ", 1, #names - 1) .. " or " .. names[#names] |
45 | return nil, "no " .. tool_options[tooltype].desc .. " tool available," .. " please install " .. tool_names .. " in your system" | ||
41 | end | 46 | end |
42 | return tool.name, vars[tool.var] .. (tool.cmdarg and " "..tool.cmdarg or "") | 47 | return tool.name, vars[tool.var] .. (tool.cmdarg and " "..tool.cmdarg or "") |
43 | end | 48 | end |
@@ -143,9 +148,12 @@ function tools.use_downloader(url, filename, cache) | |||
143 | 148 | ||
144 | filename = fs.absolute_name(filename or dir.base_name(url)) | 149 | filename = fs.absolute_name(filename or dir.base_name(url)) |
145 | 150 | ||
146 | local downloader = fs.which_tool("downloader") | 151 | local downloader, err = fs.which_tool("downloader") |
152 | if not downloader then | ||
153 | return nil, err | ||
154 | end | ||
147 | 155 | ||
148 | local ok | 156 | local ok = false |
149 | if downloader == "wget" then | 157 | if downloader == "wget" then |
150 | local wget_cmd = vars.WGET.." "..vars.WGETNOCERTFLAG.." --no-cache --user-agent=\""..cfg.user_agent.." via wget\" --quiet " | 158 | local wget_cmd = vars.WGET.." "..vars.WGETNOCERTFLAG.." --no-cache --user-agent=\""..cfg.user_agent.." via wget\" --quiet " |
151 | if cfg.connection_timeout and cfg.connection_timeout > 0 then | 159 | if cfg.connection_timeout and cfg.connection_timeout > 0 then |
@@ -172,14 +180,12 @@ function tools.use_downloader(url, filename, cache) | |||
172 | curl_cmd = curl_cmd .. " -R -z \"" .. filename .. "\" " | 180 | curl_cmd = curl_cmd .. " -R -z \"" .. filename .. "\" " |
173 | end | 181 | end |
174 | ok = fs.execute_string(fs.quiet_stderr(curl_cmd..fs.Q(url).." --output "..fs.Q(filename))) | 182 | ok = fs.execute_string(fs.quiet_stderr(curl_cmd..fs.Q(url).." --output "..fs.Q(filename))) |
175 | else | ||
176 | return false, "No downloader tool available -- please install 'wget' or 'curl' in your system" | ||
177 | end | 183 | end |
178 | if ok then | 184 | if ok then |
179 | return true, filename | 185 | return true, filename |
180 | else | 186 | else |
181 | os.remove(filename) | 187 | os.remove(filename) |
182 | return false, "Failed downloading " .. url | 188 | return false, "failed downloading " .. url |
183 | end | 189 | end |
184 | end | 190 | end |
185 | 191 | ||
@@ -188,20 +194,20 @@ end | |||
188 | -- @return string: The MD5 checksum or nil + message | 194 | -- @return string: The MD5 checksum or nil + message |
189 | function tools.get_md5(file) | 195 | function tools.get_md5(file) |
190 | local ok, md5checker = fs.which_tool("md5checker") | 196 | local ok, md5checker = fs.which_tool("md5checker") |
191 | if ok then | 197 | if not ok then |
192 | local pipe = io.popen(md5checker.." "..fs.Q(fs.absolute_name(file))) | 198 | return false, md5checker |
193 | local computed = pipe:read("*l") | 199 | end |
194 | pipe:close() | 200 | |
195 | if computed then | 201 | local pipe = io.popen(md5checker.." "..fs.Q(fs.absolute_name(file))) |
196 | computed = computed:match("("..("%x"):rep(32)..")") | 202 | local computed = pipe:read("*l") |
197 | end | 203 | pipe:close() |
198 | if computed then | 204 | if computed then |
199 | return computed | 205 | computed = computed:match("("..("%x"):rep(32)..")") |
200 | else | 206 | end |
201 | return nil, "Failed to compute MD5 hash for file "..tostring(fs.absolute_name(file)) | 207 | if computed then |
202 | end | 208 | return computed |
203 | else | 209 | else |
204 | return false, "No MD5 checking tool available -- please install 'md5', 'md5sum' or 'openssl' in your system" | 210 | return nil, "Failed to compute MD5 hash for file "..tostring(fs.absolute_name(file)) |
205 | end | 211 | end |
206 | end | 212 | end |
207 | 213 | ||