diff options
author | Peter Melnichenko <mpeterval@gmail.com> | 2016-05-07 14:12:16 +0300 |
---|---|---|
committer | Peter Melnichenko <mpeterval@gmail.com> | 2016-05-22 19:50:40 +0300 |
commit | 1cb6bb91efe3af86335453221b0f7cdcd2cb3be5 (patch) | |
tree | dcf5c9c7804691aed4de8705dead657f839a2530 | |
parent | c79ce50f956d8d9f1454ec871dc7b0469f194c07 (diff) | |
download | luarocks-1cb6bb91efe3af86335453221b0f7cdcd2cb3be5.tar.gz luarocks-1cb6bb91efe3af86335453221b0f7cdcd2cb3be5.tar.bz2 luarocks-1cb6bb91efe3af86335453221b0f7cdcd2cb3be5.zip |
fs.tools: move common 'get_md5' function
-rw-r--r-- | src/luarocks/fs/tools.lua | 22 | ||||
-rw-r--r-- | src/luarocks/fs/unix/tools.lua | 22 | ||||
-rw-r--r-- | src/luarocks/fs/win32/tools.lua | 22 |
3 files changed, 22 insertions, 44 deletions
diff --git a/src/luarocks/fs/tools.lua b/src/luarocks/fs/tools.lua index 08fa74a4..76b90383 100644 --- a/src/luarocks/fs/tools.lua +++ b/src/luarocks/fs/tools.lua | |||
@@ -100,4 +100,26 @@ function tools.use_downloader(url, filename, cache) | |||
100 | end | 100 | end |
101 | end | 101 | end |
102 | 102 | ||
103 | local md5_cmd = { | ||
104 | md5sum = fs.Q(vars.MD5SUM), | ||
105 | openssl = fs.Q(vars.OPENSSL).." md5", | ||
106 | md5 = fs.Q(vars.MD5), | ||
107 | } | ||
108 | |||
109 | --- Get the MD5 checksum for a file. | ||
110 | -- @param file string: The file to be computed. | ||
111 | -- @return string: The MD5 checksum or nil + message | ||
112 | function tools.get_md5(file) | ||
113 | local cmd = md5_cmd[cfg.md5checker] | ||
114 | if not cmd then return nil, "no MD5 checker command configured" end | ||
115 | local pipe = io.popen(cmd.." "..fs.Q(fs.absolute_name(file))) | ||
116 | local computed = pipe:read("*a") | ||
117 | pipe:close() | ||
118 | if computed then | ||
119 | computed = computed:match("("..("%x"):rep(32)..")") | ||
120 | end | ||
121 | if computed then return computed end | ||
122 | return nil, "Failed to compute MD5 hash for file "..tostring(fs.absolute_name(file)) | ||
123 | end | ||
124 | |||
103 | return tools | 125 | return tools |
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index 2b5280d6..904dd0aa 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua | |||
@@ -228,28 +228,6 @@ function tools.unpack_archive(archive) | |||
228 | return true | 228 | return true |
229 | end | 229 | end |
230 | 230 | ||
231 | local md5_cmd = { | ||
232 | md5sum = vars.MD5SUM, | ||
233 | openssl = vars.OPENSSL.." md5", | ||
234 | md5 = vars.MD5, | ||
235 | } | ||
236 | |||
237 | --- Get the MD5 checksum for a file. | ||
238 | -- @param file string: The file to be computed. | ||
239 | -- @return string: The MD5 checksum | ||
240 | function tools.get_md5(file) | ||
241 | local cmd = md5_cmd[cfg.md5checker] | ||
242 | if not cmd then return nil, "no MD5 checker command configured" end | ||
243 | local pipe = io.popen(cmd.." "..fs.Q(fs.absolute_name(file))) | ||
244 | local computed = pipe:read("*a") | ||
245 | pipe:close() | ||
246 | if computed then | ||
247 | computed = computed:match("("..("%x"):rep(32)..")") | ||
248 | end | ||
249 | if computed then return computed end | ||
250 | return nil, "Failed to compute MD5 hash for file "..tostring(fs.absolute_name(file)) | ||
251 | end | ||
252 | |||
253 | function tools.get_permissions(filename) | 231 | function tools.get_permissions(filename) |
254 | local pipe = io.popen(vars.STAT.." "..vars.STATFLAG.." "..fs.Q(filename)) | 232 | local pipe = io.popen(vars.STAT.." "..vars.STATFLAG.." "..fs.Q(filename)) |
255 | local ret = pipe:read("*l") | 233 | local ret = pipe:read("*l") |
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua index 19038e1f..f112ea3e 100644 --- a/src/luarocks/fs/win32/tools.lua +++ b/src/luarocks/fs/win32/tools.lua | |||
@@ -242,28 +242,6 @@ function tools.unpack_archive(archive) | |||
242 | return true | 242 | return true |
243 | end | 243 | end |
244 | 244 | ||
245 | local md5_cmd = { | ||
246 | md5sum = fs.Q(vars.MD5SUM), | ||
247 | openssl = fs.Q(vars.OPENSSL).." md5", | ||
248 | md5 = fs.Q(vars.MD5), | ||
249 | } | ||
250 | |||
251 | --- Get the MD5 checksum for a file. | ||
252 | -- @param file string: The file to be computed. | ||
253 | -- @return string: The MD5 checksum or nil + message | ||
254 | function tools.get_md5(file) | ||
255 | local cmd = md5_cmd[cfg.md5checker] | ||
256 | if not cmd then return nil, "no MD5 checker command configured" end | ||
257 | local pipe = io.popen(cmd.." "..fs.Q(fs.absolute_name(file))) | ||
258 | local computed = pipe:read("*a") | ||
259 | pipe:close() | ||
260 | if computed then | ||
261 | computed = computed:match("("..("%x"):rep(32)..")") | ||
262 | end | ||
263 | if computed then return computed end | ||
264 | return nil, "Failed to compute MD5 hash for file "..tostring(fs.absolute_name(file)) | ||
265 | end | ||
266 | |||
267 | --- Test for existance of a file. | 245 | --- Test for existance of a file. |
268 | -- @param file string: filename to test | 246 | -- @param file string: filename to test |
269 | -- @return boolean: true if file exists, false otherwise. | 247 | -- @return boolean: true if file exists, false otherwise. |