From 1ae81cea573bcaf3baefbd2cdba6b5a5976716d5 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Tue, 23 Nov 2010 22:34:51 -0200 Subject: Use unified matcher for md5 commands, as suggested by Doug Currie. --- src/luarocks/fs/unix/tools.lua | 40 ++++++++++++++-------------------------- src/luarocks/fs/win32/tools.lua | 40 ++++++++++++++-------------------------- 2 files changed, 28 insertions(+), 52 deletions(-) (limited to 'src') 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) return true end +local md5_cmd = { + md5sum = "md5sum ", + openssl = "openssl md5 ", + md5 = "md5 ", +} + --- Get the MD5 checksum for a file. -- @param file string: The file to be computed. -- @return string: The MD5 checksum -function get_md5(file, md5sum) - file = fs.absolute_name(file) - local computed - if cfg.md5checker == "md5sum" then - local pipe = io.popen("md5sum "..file) - computed = pipe:read("*a") - pipe:close() - if computed then - computed = computed:gsub("[^%x]+", ""):sub(1,32) - end - elseif cfg.md5checker == "openssl" then - local pipe = io.popen("openssl md5 "..file) - computed = pipe:read("*l") - pipe:close() - if computed then - computed = computed:sub(-32) - end - elseif cfg.md5checker == "md5" then - local pipe = io.popen("md5 "..file) - computed = pipe:read("*l") - pipe:close() - if computed then - computed = computed:sub(-32) - end - end - return computed +function get_md5(file) + local cmd = md5_cmd[cfg.md5checker] + if not cmd then return nil end + local pipe = io.popen(cmd..fs.absolute_name(file)) + local computed = pipe:read("*a") + pipe:close() + if not computed then return nil end + return computed:match("("..("%x"):rep(32)..")") end --- 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) return fs.execute("test -f", file) end +local md5_cmd = { + md5sum = "md5sum ", + openssl = "openssl md5 ", + md5 = "md5 ", +} + --- Get the MD5 checksum for a file. -- @param file string: The file to be computed. -- @return string: The MD5 checksum -function get_md5(file, md5sum) - file = fs.absolute_name(file) - local computed - if cfg.md5checker == "md5sum" then - local pipe = io.popen("md5sum "..file) - computed = pipe:read("*l") - pipe:close() - if computed then - computed = computed:gsub("[^%x]+", ""):sub(1,32) - end - elseif cfg.md5checker == "openssl" then - local pipe = io.popen("openssl md5 "..file) - computed = pipe:read("*l") - pipe:close() - if computed then - computed = computed:sub(-32) - end - elseif cfg.md5checker == "md5" then - local pipe = io.popen("md5 "..file) - computed = pipe:read("*l") - pipe:close() - if computed then - computed = computed:sub(-32) - end - end - return computed +function get_md5(file) + local cmd = md5_cmd[cfg.md5checker] + if not cmd then return nil end + local pipe = io.popen(cmd..fs.absolute_name(file)) + local computed = pipe:read("*a") + pipe:close() + if not computed then return nil end + return computed:match("("..("%x"):rep(32)..")") end --- Change the current directory. -- cgit v1.2.3-55-g6feb From b113a72b63d494828bb6b28833cc53de21b02aeb Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sat, 4 Dec 2010 15:20:42 -0200 Subject: remove unused variable --- src/luarocks/persist.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/luarocks/persist.lua b/src/luarocks/persist.lua index 293b5e93..70a89b8d 100644 --- a/src/luarocks/persist.lua +++ b/src/luarocks/persist.lua @@ -34,7 +34,6 @@ end -- @param tbl table: the table to be written. local function write_table(out, tbl, level) out:write("{") - local size = table.getn(tbl) local sep = "\n" local indent = true local i = 1 -- cgit v1.2.3-55-g6feb From a90a0d3ec2783df75343d366d4b52e586b42f6e6 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sun, 5 Dec 2010 13:57:46 -0200 Subject: Make sorting for manifest table stable. --- src/luarocks/persist.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/luarocks/persist.lua b/src/luarocks/persist.lua index 70a89b8d..d74a805e 100644 --- a/src/luarocks/persist.lua +++ b/src/luarocks/persist.lua @@ -5,6 +5,8 @@ -- as it is used in the bootstrapping stage of the cfg module. module("luarocks.persist", package.seeall) +local util = require("luarocks.util") + --- Load a Lua file containing assignments, storing them in a table. -- The global environment is not propagated to the loaded file. -- @param filename string: the name of the file. @@ -26,6 +28,10 @@ function load_into_table(filename, tbl) return result end +local function string_sort(a,b) + return tostring(a) < tostring(b) +end + --- Write a table as Lua code representing a table to disk -- (that is, in curly brackets notation). -- This function handles only numbers, strings and tables @@ -37,7 +43,7 @@ local function write_table(out, tbl, level) local sep = "\n" local indent = true local i = 1 - for k, v in pairs(tbl) do + for k, v in util.sortedpairs(tbl, string_sort) do out:write(sep) if indent then for n = 1,level do out:write(" ") end @@ -89,7 +95,7 @@ function save_from_table(filename, tbl) if not out then return nil, "Cannot create file at "..filename end - for k, v in pairs(tbl) do + for k, v in util.sortedpairs(tbl, string_sort) do out:write(k.." = ") write_table(out, v, 1) out:write("\n") -- cgit v1.2.3-55-g6feb