aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2018-06-25 16:25:12 -0300
committerHisham Muhammad <hisham@gobolinux.org>2018-07-01 15:51:36 -0300
commit35ccc9c05e79f2433cf22a3c02eddfa5a15fdf38 (patch)
tree00e639a6722211bf1de1ad648e9aa112d9d5b778 /src
parent9734fd3fec39aa53d52ef8fb45ef974ac27ecf89 (diff)
downloadluarocks-35ccc9c05e79f2433cf22a3c02eddfa5a15fdf38.tar.gz
luarocks-35ccc9c05e79f2433cf22a3c02eddfa5a15fdf38.tar.bz2
luarocks-35ccc9c05e79f2433cf22a3c02eddfa5a15fdf38.zip
fs: do not cache cfg.variables
Avoid relying on the order that cfg and fs are required. This is not strictly required in regular operation, but it allows us to mock cfg and use fs.
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/fs/tools.lua42
-rw-r--r--src/luarocks/fs/unix/tools.lua2
-rw-r--r--src/luarocks/fs/win32/tools.lua2
3 files changed, 21 insertions, 25 deletions
diff --git a/src/luarocks/fs/tools.lua b/src/luarocks/fs/tools.lua
index 671c7ae1..8f4dd1a5 100644
--- a/src/luarocks/fs/tools.lua
+++ b/src/luarocks/fs/tools.lua
@@ -6,7 +6,7 @@ local fs = require("luarocks.fs")
6local dir = require("luarocks.dir") 6local dir = require("luarocks.dir")
7local cfg = require("luarocks.core.cfg") 7local cfg = require("luarocks.core.cfg")
8 8
9local vars = cfg.variables 9local vars = setmetatable({}, { __index = function(_,k) return cfg.variables[k] end })
10 10
11local dir_stack = {} 11local dir_stack = {}
12 12
@@ -20,23 +20,26 @@ do
20 }, 20 },
21 md5checker = { 21 md5checker = {
22 { var = "MD5SUM", name = "md5sum" }, 22 { var = "MD5SUM", name = "md5sum" },
23 { var = "OPENSSL", name = "openssl" }, 23 { var = "OPENSSL", name = "openssl", cmdarg = "md5" },
24 { var = "MD5", name = "md5", arg = "-v" }, 24 { var = "MD5", name = "md5", checkarg = "-v" },
25 }, 25 },
26 } 26 }
27 27
28 function tools.which_tool(tooltype) 28 function tools.which_tool(tooltype)
29 if tool_cache[tooltype] then 29 local tool = tool_cache[tooltype]
30 return tool_cache[tooltype] 30 if not tool then
31 end 31 for _, opt in ipairs(tool_options[tooltype]) do
32 32 if fs.is_tool_available(vars[opt.var], opt.name, opt.checkarg) then
33 for _, opt in ipairs(tool_options[tooltype]) do 33 tool = opt
34 if fs.is_tool_available(vars[opt.var], opt.name, opt.arg) then 34 tool_cache[tooltype] = opt
35 tool_cache[tooltype] = opt.name 35 break
36 break 36 end
37 end 37 end
38 end 38 end
39 return tool_cache[tooltype] 39 if not tool then
40 return nil
41 end
42 return tool.name, fs.Q(vars[tool.var]) .. (tool.cmdarg and " "..tool.cmdarg or "")
40 end 43 end
41end 44end
42 45
@@ -169,20 +172,13 @@ function tools.use_downloader(url, filename, cache)
169 end 172 end
170end 173end
171 174
172local md5_cmd = {
173 md5sum = fs.Q(vars.MD5SUM),
174 openssl = fs.Q(vars.OPENSSL).." md5",
175 md5 = fs.Q(vars.MD5),
176}
177
178--- Get the MD5 checksum for a file. 175--- Get the MD5 checksum for a file.
179-- @param file string: The file to be computed. 176-- @param file string: The file to be computed.
180-- @return string: The MD5 checksum or nil + message 177-- @return string: The MD5 checksum or nil + message
181function tools.get_md5(file) 178function tools.get_md5(file)
182 local md5checker = fs.which_tool("md5checker") 179 local ok, md5checker = fs.which_tool("md5checker")
183 if md5checker then 180 if ok then
184 local cmd = md5_cmd[md5checker] 181 local pipe = io.popen(md5checker.." "..fs.Q(fs.absolute_name(file)))
185 local pipe = io.popen(cmd.." "..fs.Q(fs.absolute_name(file)))
186 local computed = pipe:read("*l") 182 local computed = pipe:read("*l")
187 pipe:close() 183 pipe:close()
188 if computed then 184 if computed then
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua
index e0b0d22a..6a91775f 100644
--- a/src/luarocks/fs/unix/tools.lua
+++ b/src/luarocks/fs/unix/tools.lua
@@ -6,7 +6,7 @@ local fs = require("luarocks.fs")
6local dir = require("luarocks.dir") 6local dir = require("luarocks.dir")
7local cfg = require("luarocks.core.cfg") 7local cfg = require("luarocks.core.cfg")
8 8
9local vars = cfg.variables 9local vars = setmetatable({}, { __index = function(_,k) return cfg.variables[k] end })
10 10
11--- Adds prefix to command to make it run from a directory. 11--- Adds prefix to command to make it run from a directory.
12-- @param directory string: Path to a directory. 12-- @param directory string: Path to a directory.
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua
index d0a7d8b2..c03b0d7b 100644
--- a/src/luarocks/fs/win32/tools.lua
+++ b/src/luarocks/fs/win32/tools.lua
@@ -8,7 +8,7 @@ local fs = require("luarocks.fs")
8local dir = require("luarocks.dir") 8local dir = require("luarocks.dir")
9local cfg = require("luarocks.core.cfg") 9local cfg = require("luarocks.core.cfg")
10 10
11local vars = cfg.variables 11local vars = setmetatable({}, { __index = function(_,k) return cfg.variables[k] end })
12 12
13--- Adds prefix to command to make it run from a directory. 13--- Adds prefix to command to make it run from a directory.
14-- @param directory string: Path to a directory. 14-- @param directory string: Path to a directory.