aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2010-11-23 22:34:51 -0200
committerHisham Muhammad <hisham@gobolinux.org>2010-11-23 22:34:51 -0200
commit1ae81cea573bcaf3baefbd2cdba6b5a5976716d5 (patch)
treef058b7b04edc1cf161a5112ef8a035f3b3166ed5
parent98ead176473c0fbd02b147adbcb089df8a56095e (diff)
downloadluarocks-1ae81cea573bcaf3baefbd2cdba6b5a5976716d5.tar.gz
luarocks-1ae81cea573bcaf3baefbd2cdba6b5a5976716d5.tar.bz2
luarocks-1ae81cea573bcaf3baefbd2cdba6b5a5976716d5.zip
Use unified matcher for md5 commands, as suggested by Doug Currie.
-rw-r--r--src/luarocks/fs/unix/tools.lua40
-rw-r--r--src/luarocks/fs/win32/tools.lua40
2 files changed, 28 insertions, 52 deletions
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua
index c805fb48..691c2648 100644
--- a/src/luarocks/fs/unix/tools.lua
+++ b/src/luarocks/fs/unix/tools.lua
@@ -287,35 +287,23 @@ function unpack_archive(archive)
287 return true 287 return true
288end 288end
289 289
290local md5_cmd = {
291 md5sum = "md5sum ",
292 openssl = "openssl md5 ",
293 md5 = "md5 ",
294}
295
290--- Get the MD5 checksum for a file. 296--- Get the MD5 checksum for a file.
291-- @param file string: The file to be computed. 297-- @param file string: The file to be computed.
292-- @return string: The MD5 checksum 298-- @return string: The MD5 checksum
293function get_md5(file, md5sum) 299function get_md5(file)
294 file = fs.absolute_name(file) 300 local cmd = md5_cmd[cfg.md5checker]
295 local computed 301 if not cmd then return nil end
296 if cfg.md5checker == "md5sum" then 302 local pipe = io.popen(cmd..fs.absolute_name(file))
297 local pipe = io.popen("md5sum "..file) 303 local computed = pipe:read("*a")
298 computed = pipe:read("*a") 304 pipe:close()
299 pipe:close() 305 if not computed then return nil end
300 if computed then 306 return computed:match("("..("%x"):rep(32)..")")
301 computed = computed:gsub("[^%x]+", ""):sub(1,32)
302 end
303 elseif cfg.md5checker == "openssl" then
304 local pipe = io.popen("openssl md5 "..file)
305 computed = pipe:read("*l")
306 pipe:close()
307 if computed then
308 computed = computed:sub(-32)
309 end
310 elseif cfg.md5checker == "md5" then
311 local pipe = io.popen("md5 "..file)
312 computed = pipe:read("*l")
313 pipe:close()
314 if computed then
315 computed = computed:sub(-32)
316 end
317 end
318 return computed
319end 307end
320 308
321--- Unpack an archive. 309--- Unpack an archive.
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua
index d2613b67..9e891fca 100644
--- a/src/luarocks/fs/win32/tools.lua
+++ b/src/luarocks/fs/win32/tools.lua
@@ -62,35 +62,23 @@ function is_file(file)
62 return fs.execute("test -f", file) 62 return fs.execute("test -f", file)
63end 63end
64 64
65local md5_cmd = {
66 md5sum = "md5sum ",
67 openssl = "openssl md5 ",
68 md5 = "md5 ",
69}
70
65--- Get the MD5 checksum for a file. 71--- Get the MD5 checksum for a file.
66-- @param file string: The file to be computed. 72-- @param file string: The file to be computed.
67-- @return string: The MD5 checksum 73-- @return string: The MD5 checksum
68function get_md5(file, md5sum) 74function get_md5(file)
69 file = fs.absolute_name(file) 75 local cmd = md5_cmd[cfg.md5checker]
70 local computed 76 if not cmd then return nil end
71 if cfg.md5checker == "md5sum" then 77 local pipe = io.popen(cmd..fs.absolute_name(file))
72 local pipe = io.popen("md5sum "..file) 78 local computed = pipe:read("*a")
73 computed = pipe:read("*l") 79 pipe:close()
74 pipe:close() 80 if not computed then return nil end
75 if computed then 81 return computed:match("("..("%x"):rep(32)..")")
76 computed = computed:gsub("[^%x]+", ""):sub(1,32)
77 end
78 elseif cfg.md5checker == "openssl" then
79 local pipe = io.popen("openssl md5 "..file)
80 computed = pipe:read("*l")
81 pipe:close()
82 if computed then
83 computed = computed:sub(-32)
84 end
85 elseif cfg.md5checker == "md5" then
86 local pipe = io.popen("md5 "..file)
87 computed = pipe:read("*l")
88 pipe:close()
89 if computed then
90 computed = computed:sub(-32)
91 end
92 end
93 return computed
94end 82end
95 83
96--- Change the current directory. 84--- Change the current directory.