diff options
| author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2013-11-13 15:29:31 +0100 |
|---|---|---|
| committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2013-11-13 15:29:31 +0100 |
| commit | 217a43551fae3bff78e6fabef8f29919e252ac15 (patch) | |
| tree | 7e424c64e98f4fda5ce609cab85b539266fd8799 /src | |
| parent | 370a2943c09e70154862f382fe3de7f486a4a1c6 (diff) | |
| download | luarocks-217a43551fae3bff78e6fabef8f29919e252ac15.tar.gz luarocks-217a43551fae3bff78e6fabef8f29919e252ac15.tar.bz2 luarocks-217a43551fae3bff78e6fabef8f29919e252ac15.zip | |
update get_md5() and check_md5() to also return an error message if it fails
unquoted arguments of get_md5 command to prevent failure, needs further updating
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/fs/lua.lua | 15 | ||||
| -rw-r--r-- | src/luarocks/fs/unix/tools.lua | 7 | ||||
| -rw-r--r-- | src/luarocks/fs/win32/tools.lua | 11 |
3 files changed, 20 insertions, 13 deletions
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 51cbee03..f9ec43ba 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
| @@ -123,18 +123,18 @@ end | |||
| 123 | --- Check the MD5 checksum for a file. | 123 | --- Check the MD5 checksum for a file. |
| 124 | -- @param file string: The file to be checked. | 124 | -- @param file string: The file to be checked. |
| 125 | -- @param md5sum string: The string with the expected MD5 checksum. | 125 | -- @param md5sum string: The string with the expected MD5 checksum. |
| 126 | -- @return boolean: true if the MD5 checksum for 'file' equals 'md5sum', false if not | 126 | -- @return boolean: true if the MD5 checksum for 'file' equals 'md5sum', false + msg if not |
| 127 | -- or if it could not perform the check for any reason. | 127 | -- or if it could not perform the check for any reason. |
| 128 | function check_md5(file, md5sum) | 128 | function check_md5(file, md5sum) |
| 129 | file = dir.normalize(file) | 129 | file = dir.normalize(file) |
| 130 | local computed = fs.get_md5(file) | 130 | local computed, msg = fs.get_md5(file) |
| 131 | if not computed then | 131 | if not computed then |
| 132 | return false | 132 | return false, msg |
| 133 | end | 133 | end |
| 134 | if computed:match("^"..md5sum) then | 134 | if computed:match("^"..md5sum) then |
| 135 | return true | 135 | return true |
| 136 | else | 136 | else |
| 137 | return false | 137 | return false, "Mismatch MD5 hash for file "..file |
| 138 | end | 138 | end |
| 139 | end | 139 | end |
| 140 | 140 | ||
| @@ -648,14 +648,15 @@ if md5_ok then | |||
| 648 | 648 | ||
| 649 | --- Get the MD5 checksum for a file. | 649 | --- Get the MD5 checksum for a file. |
| 650 | -- @param file string: The file to be computed. | 650 | -- @param file string: The file to be computed. |
| 651 | -- @return string: The MD5 checksum | 651 | -- @return string: The MD5 checksum or nil + error |
| 652 | function get_md5(file) | 652 | function get_md5(file) |
| 653 | file = fs.absolute_name(file) | 653 | file = fs.absolute_name(file) |
| 654 | local file = io.open(file, "rb") | 654 | local file = io.open(file, "rb") |
| 655 | if not file then return false end | 655 | if not file then return nil, "Failed to compute MD5 hash for file "..file end |
| 656 | local computed = md5.sumhexa(file:read("*a")) | 656 | local computed = md5.sumhexa(file:read("*a")) |
| 657 | file:close() | 657 | file:close() |
| 658 | return computed | 658 | if computed then return computed end |
| 659 | return nil, "Failed to compute MD5 hash for file "..file | ||
| 659 | end | 660 | end |
| 660 | 661 | ||
| 661 | end | 662 | end |
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index e3468ab4..c857b093 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua | |||
| @@ -328,8 +328,11 @@ function get_md5(file) | |||
| 328 | local pipe = io.popen(cmd.." "..fs.absolute_name(file)) | 328 | local pipe = io.popen(cmd.." "..fs.absolute_name(file)) |
| 329 | local computed = pipe:read("*a") | 329 | local computed = pipe:read("*a") |
| 330 | pipe:close() | 330 | pipe:close() |
| 331 | if not computed then return nil end | 331 | if computed then |
| 332 | return computed:match("("..("%x"):rep(32)..")") | 332 | computed = computed:match("("..("%x"):rep(32)..")") |
| 333 | end | ||
| 334 | if computed then return computed end | ||
| 335 | return nil, "Failed to compute MD5 hash for file "..tostring(fs.absolute_name(file)) | ||
| 333 | end | 336 | end |
| 334 | 337 | ||
| 335 | function get_permissions(filename) | 338 | function get_permissions(filename) |
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua index 9aa76851..1c0131c7 100644 --- a/src/luarocks/fs/win32/tools.lua +++ b/src/luarocks/fs/win32/tools.lua | |||
| @@ -353,15 +353,18 @@ local md5_cmd = { | |||
| 353 | 353 | ||
| 354 | --- Get the MD5 checksum for a file. | 354 | --- Get the MD5 checksum for a file. |
| 355 | -- @param file string: The file to be computed. | 355 | -- @param file string: The file to be computed. |
| 356 | -- @return string: The MD5 checksum | 356 | -- @return string: The MD5 checksum or nil + message |
| 357 | function get_md5(file) | 357 | function get_md5(file) |
| 358 | local cmd = md5_cmd[cfg.md5checker] | 358 | local cmd = md5_cmd[cfg.md5checker] |
| 359 | if not cmd then return nil end | 359 | if not cmd then return nil end |
| 360 | local pipe = io.popen(cmd.." "..fs.Q(fs.absolute_name(file))) | 360 | local pipe = io.popen(cmd.." "..fs.absolute_name(file)) -- should be in fs.Q() |
| 361 | local computed = pipe:read("*a") | 361 | local computed = pipe:read("*a") |
| 362 | pipe:close() | 362 | pipe:close() |
| 363 | if not computed then return nil end | 363 | if computed then |
| 364 | return computed:match("("..("%x"):rep(32)..")") | 364 | computed = computed:match("("..("%x"):rep(32)..")") |
| 365 | end | ||
| 366 | if computed then return computed end | ||
| 367 | return nil, "Failed to compute MD5 hash for file "..tostring(fs.absolute_name(file)) | ||
| 365 | end | 368 | end |
| 366 | 369 | ||
| 367 | --- Test for existance of a file. | 370 | --- Test for existance of a file. |
