diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2010-12-14 11:57:15 -0200 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2010-12-14 11:57:15 -0200 |
| commit | 799736f057658d05446c722b4e157d48aff86a2e (patch) | |
| tree | 1e2a9005b504382162a59c5da9fe8cd22be214c5 /src | |
| parent | a80e64ce3eb0e5e3abe48bc18ed2acbad8253002 (diff) | |
| parent | a90a0d3ec2783df75343d366d4b52e586b42f6e6 (diff) | |
| download | luarocks-799736f057658d05446c722b4e157d48aff86a2e.tar.gz luarocks-799736f057658d05446c722b4e157d48aff86a2e.tar.bz2 luarocks-799736f057658d05446c722b4e157d48aff86a2e.zip | |
Merge branch 'master' of github.com:keplerproject/luarocks
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/fs/unix/tools.lua | 40 | ||||
| -rw-r--r-- | src/luarocks/fs/win32/tools.lua | 40 | ||||
| -rw-r--r-- | src/luarocks/persist.lua | 11 |
3 files changed, 36 insertions, 55 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 |
| 288 | end | 288 | end |
| 289 | 289 | ||
| 290 | local 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 |
| 293 | function get_md5(file, md5sum) | 299 | function 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 | ||
| 319 | end | 307 | end |
| 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) |
| 63 | end | 63 | end |
| 64 | 64 | ||
| 65 | local 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 |
| 68 | function get_md5(file, md5sum) | 74 | function 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 | ||
| 94 | end | 82 | end |
| 95 | 83 | ||
| 96 | --- Change the current directory. | 84 | --- Change the current directory. |
diff --git a/src/luarocks/persist.lua b/src/luarocks/persist.lua index 293b5e93..d74a805e 100644 --- a/src/luarocks/persist.lua +++ b/src/luarocks/persist.lua | |||
| @@ -5,6 +5,8 @@ | |||
| 5 | -- as it is used in the bootstrapping stage of the cfg module. | 5 | -- as it is used in the bootstrapping stage of the cfg module. |
| 6 | module("luarocks.persist", package.seeall) | 6 | module("luarocks.persist", package.seeall) |
| 7 | 7 | ||
| 8 | local util = require("luarocks.util") | ||
| 9 | |||
| 8 | --- Load a Lua file containing assignments, storing them in a table. | 10 | --- Load a Lua file containing assignments, storing them in a table. |
| 9 | -- The global environment is not propagated to the loaded file. | 11 | -- The global environment is not propagated to the loaded file. |
| 10 | -- @param filename string: the name of the file. | 12 | -- @param filename string: the name of the file. |
| @@ -26,6 +28,10 @@ function load_into_table(filename, tbl) | |||
| 26 | return result | 28 | return result |
| 27 | end | 29 | end |
| 28 | 30 | ||
| 31 | local function string_sort(a,b) | ||
| 32 | return tostring(a) < tostring(b) | ||
| 33 | end | ||
| 34 | |||
| 29 | --- Write a table as Lua code representing a table to disk | 35 | --- Write a table as Lua code representing a table to disk |
| 30 | -- (that is, in curly brackets notation). | 36 | -- (that is, in curly brackets notation). |
| 31 | -- This function handles only numbers, strings and tables | 37 | -- This function handles only numbers, strings and tables |
| @@ -34,11 +40,10 @@ end | |||
| 34 | -- @param tbl table: the table to be written. | 40 | -- @param tbl table: the table to be written. |
| 35 | local function write_table(out, tbl, level) | 41 | local function write_table(out, tbl, level) |
| 36 | out:write("{") | 42 | out:write("{") |
| 37 | local size = table.getn(tbl) | ||
| 38 | local sep = "\n" | 43 | local sep = "\n" |
| 39 | local indent = true | 44 | local indent = true |
| 40 | local i = 1 | 45 | local i = 1 |
| 41 | for k, v in pairs(tbl) do | 46 | for k, v in util.sortedpairs(tbl, string_sort) do |
| 42 | out:write(sep) | 47 | out:write(sep) |
| 43 | if indent then | 48 | if indent then |
| 44 | for n = 1,level do out:write(" ") end | 49 | for n = 1,level do out:write(" ") end |
| @@ -90,7 +95,7 @@ function save_from_table(filename, tbl) | |||
| 90 | if not out then | 95 | if not out then |
| 91 | return nil, "Cannot create file at "..filename | 96 | return nil, "Cannot create file at "..filename |
| 92 | end | 97 | end |
| 93 | for k, v in pairs(tbl) do | 98 | for k, v in util.sortedpairs(tbl, string_sort) do |
| 94 | out:write(k.." = ") | 99 | out:write(k.." = ") |
| 95 | write_table(out, v, 1) | 100 | write_table(out, v, 1) |
| 96 | out:write("\n") | 101 | out:write("\n") |
