diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2013-12-05 18:10:26 -0200 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2013-12-05 18:10:26 -0200 |
| commit | 8fde71c60da90eca1103b6df9847542caf766131 (patch) | |
| tree | b68afdb4f2eceda41d8d44ae763fc0b43f701765 /src | |
| parent | 7734e610adf908f1b3a572f3bdaf796be26923f0 (diff) | |
| parent | 4f9ee18078fcd6b1fd810630b1e86f2b63fe17b8 (diff) | |
| download | luarocks-8fde71c60da90eca1103b6df9847542caf766131.tar.gz luarocks-8fde71c60da90eca1103b6df9847542caf766131.tar.bz2 luarocks-8fde71c60da90eca1103b6df9847542caf766131.zip | |
Merge branch 'master' of github.com:keplerproject/luarocks
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/cfg.lua | 2 | ||||
| -rw-r--r-- | src/luarocks/fs.lua | 26 | ||||
| -rw-r--r-- | src/luarocks/fs/lua.lua | 25 | ||||
| -rw-r--r-- | src/luarocks/fs/unix/tools.lua | 7 | ||||
| -rw-r--r-- | src/luarocks/fs/win32.lua | 39 | ||||
| -rw-r--r-- | src/luarocks/fs/win32/tools.lua | 61 |
6 files changed, 112 insertions, 48 deletions
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index e3d924fb..f66ad1d9 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua | |||
| @@ -322,7 +322,7 @@ if detected.windows then | |||
| 322 | local localappdata = os.getenv("LOCALAPPDATA") | 322 | local localappdata = os.getenv("LOCALAPPDATA") |
| 323 | if not localappdata then | 323 | if not localappdata then |
| 324 | -- for Windows versions below Vista | 324 | -- for Windows versions below Vista |
| 325 | localappdata = os.getenv("USER_PROFILE").."/Local Settings/Application Data" | 325 | localappdata = os.getenv("USERPROFILE").."/Local Settings/Application Data" |
| 326 | end | 326 | end |
| 327 | defaults.local_cache = localappdata.."/LuaRocks/Cache" | 327 | defaults.local_cache = localappdata.."/LuaRocks/Cache" |
| 328 | end | 328 | end |
diff --git a/src/luarocks/fs.lua b/src/luarocks/fs.lua index 467b1943..2d799da2 100644 --- a/src/luarocks/fs.lua +++ b/src/luarocks/fs.lua | |||
| @@ -11,6 +11,32 @@ module("luarocks.fs", package.seeall) | |||
| 11 | 11 | ||
| 12 | local cfg = require("luarocks.cfg") | 12 | local cfg = require("luarocks.cfg") |
| 13 | 13 | ||
| 14 | local pack = table.pack or function(...) return { n = select("#", ...), ... } end | ||
| 15 | local unpack = table.unpack or unpack | ||
| 16 | |||
| 17 | if cfg.verbose then -- patch io.popen and os.execute to display commands in verbose mode | ||
| 18 | old_popen = io.popen | ||
| 19 | io.popen = function(one, two) | ||
| 20 | if two == nil then | ||
| 21 | print("\nio.popen: ", one) | ||
| 22 | else | ||
| 23 | print("\nio.popen: ", one, "Mode:", two) | ||
| 24 | end | ||
| 25 | return old_popen(one, two) | ||
| 26 | end | ||
| 27 | |||
| 28 | old_exec = os.execute | ||
| 29 | os.execute = function(cmd) | ||
| 30 | print("\nos.execute: ", cmd) | ||
| 31 | local code = pack(old_exec(cmd)) | ||
| 32 | print("Results: "..tostring(code.n)) | ||
| 33 | for i = 1,code.n do | ||
| 34 | print(" "..tostring(i).." ("..type(code[i]).."): "..tostring(code[i])) | ||
| 35 | end | ||
| 36 | return unpack(code, 1, code.n) | ||
| 37 | end | ||
| 38 | end | ||
| 39 | |||
| 14 | local function load_fns(fs_table) | 40 | local function load_fns(fs_table) |
| 15 | for name, fn in pairs(fs_table) do | 41 | for name, fn in pairs(fs_table) do |
| 16 | if not _M[name] then | 42 | if not _M[name] then |
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index d477d88f..5f7d6c37 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
| @@ -106,31 +106,36 @@ end | |||
| 106 | 106 | ||
| 107 | --- Run the given command, quoting its arguments, silencing its output. | 107 | --- Run the given command, quoting its arguments, silencing its output. |
| 108 | -- The command is executed in the current directory in the dir stack. | 108 | -- The command is executed in the current directory in the dir stack. |
| 109 | -- Silencing is omitted if 'verbose' mode is enabled. | ||
| 109 | -- @param command string: The command to be executed. No quoting/escaping | 110 | -- @param command string: The command to be executed. No quoting/escaping |
| 110 | -- is applied. | 111 | -- is applied. |
| 111 | -- @param ... Strings containing additional arguments, which are quoted. | 112 | -- @param ... Strings containing additional arguments, which will be quoted. |
| 112 | -- @return boolean: true if command succeeds (status code 0), false | 113 | -- @return boolean: true if command succeeds (status code 0), false |
| 113 | -- otherwise. | 114 | -- otherwise. |
| 114 | function execute_quiet(command, ...) | 115 | function execute_quiet(command, ...) |
| 115 | assert(type(command) == "string") | 116 | assert(type(command) == "string") |
| 116 | return fs.execute_string(fs.quiet(quote_args(command, ...))) | 117 | if cfg.verbose then -- omit silencing output |
| 118 | return fs.execute_string(quote_args(command, ...)) | ||
| 119 | else | ||
| 120 | return fs.execute_string(fs.quiet(quote_args(command, ...))) | ||
| 121 | end | ||
| 117 | end | 122 | end |
| 118 | 123 | ||
| 119 | --- Check the MD5 checksum for a file. | 124 | --- Check the MD5 checksum for a file. |
| 120 | -- @param file string: The file to be checked. | 125 | -- @param file string: The file to be checked. |
| 121 | -- @param md5sum string: The string with the expected MD5 checksum. | 126 | -- @param md5sum string: The string with the expected MD5 checksum. |
| 122 | -- @return boolean: true if the MD5 checksum for 'file' equals 'md5sum', false if not | 127 | -- @return boolean: true if the MD5 checksum for 'file' equals 'md5sum', false + msg if not |
| 123 | -- or if it could not perform the check for any reason. | 128 | -- or if it could not perform the check for any reason. |
| 124 | function check_md5(file, md5sum) | 129 | function check_md5(file, md5sum) |
| 125 | file = dir.normalize(file) | 130 | file = dir.normalize(file) |
| 126 | local computed = fs.get_md5(file) | 131 | local computed, msg = fs.get_md5(file) |
| 127 | if not computed then | 132 | if not computed then |
| 128 | return false | 133 | return false, msg |
| 129 | end | 134 | end |
| 130 | if computed:match("^"..md5sum) then | 135 | if computed:match("^"..md5sum) then |
| 131 | return true | 136 | return true |
| 132 | else | 137 | else |
| 133 | return false | 138 | return false, "Mismatch MD5 hash for file "..file |
| 134 | end | 139 | end |
| 135 | end | 140 | end |
| 136 | 141 | ||
| @@ -146,7 +151,6 @@ if lfs_ok then | |||
| 146 | -- @return boolean: true if command succeeds (status code 0), false | 151 | -- @return boolean: true if command succeeds (status code 0), false |
| 147 | -- otherwise. | 152 | -- otherwise. |
| 148 | function execute_string(cmd) | 153 | function execute_string(cmd) |
| 149 | if cfg.verbose then print("Executing: "..cmd) end | ||
| 150 | local code = os.execute(cmd) | 154 | local code = os.execute(cmd) |
| 151 | return (code == 0 or code == true) | 155 | return (code == 0 or code == true) |
| 152 | end | 156 | end |
| @@ -644,14 +648,15 @@ if md5_ok then | |||
| 644 | 648 | ||
| 645 | --- Get the MD5 checksum for a file. | 649 | --- Get the MD5 checksum for a file. |
| 646 | -- @param file string: The file to be computed. | 650 | -- @param file string: The file to be computed. |
| 647 | -- @return string: The MD5 checksum | 651 | -- @return string: The MD5 checksum or nil + error |
| 648 | function get_md5(file) | 652 | function get_md5(file) |
| 649 | file = fs.absolute_name(file) | 653 | file = fs.absolute_name(file) |
| 650 | local file = io.open(file, "rb") | 654 | local file = io.open(file, "rb") |
| 651 | if not file then return false end | 655 | if not file then return nil, "Failed to compute MD5 hash for file "..file end |
| 652 | local computed = md5.sumhexa(file:read("*a")) | 656 | local computed = md5.sumhexa(file:read("*a")) |
| 653 | file:close() | 657 | file:close() |
| 654 | return computed | 658 | if computed then return computed end |
| 659 | return nil, "Failed to compute MD5 hash for file "..file | ||
| 655 | end | 660 | end |
| 656 | 661 | ||
| 657 | 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.lua b/src/luarocks/fs/win32.lua index 0280b3f0..a3f0663b 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua | |||
| @@ -9,6 +9,15 @@ local cfg = require("luarocks.cfg") | |||
| 9 | local dir = require("luarocks.dir") | 9 | local dir = require("luarocks.dir") |
| 10 | local util = require("luarocks.util") | 10 | local util = require("luarocks.util") |
| 11 | 11 | ||
| 12 | -- Monkey patch io.popen and os.execute to make sure quoting | ||
| 13 | -- works as expected. | ||
| 14 | -- See http://lua-users.org/lists/lua-l/2013-11/msg00367.html | ||
| 15 | local _prefix = "type NUL && " | ||
| 16 | local _popen, _execute = io.popen, os.execute | ||
| 17 | io.popen = function(cmd, ...) return _popen(_prefix..cmd, ...) end | ||
| 18 | os.execute = function(cmd, ...) return _execute(_prefix..cmd, ...) end | ||
| 19 | |||
| 20 | |||
| 12 | --- Annotate command string for quiet execution. | 21 | --- Annotate command string for quiet execution. |
| 13 | -- @param cmd string: A command-line string. | 22 | -- @param cmd string: A command-line string. |
| 14 | -- @return string: The command-line, with silencing annotation. | 23 | -- @return string: The command-line, with silencing annotation. |
| @@ -173,3 +182,33 @@ function replace_file(old_file, new_file) | |||
| 173 | return os.rename(new_file, old_file) | 182 | return os.rename(new_file, old_file) |
| 174 | end | 183 | end |
| 175 | 184 | ||
| 185 | --- Test is file/dir is writable. | ||
| 186 | -- Warning: testing if a file/dir is writable does not guarantee | ||
| 187 | -- that it will remain writable and therefore it is no replacement | ||
| 188 | -- for checking the result of subsequent operations. | ||
| 189 | -- @param file string: filename to test | ||
| 190 | -- @return boolean: true if file exists, false otherwise. | ||
| 191 | function is_writable(file) | ||
| 192 | assert(file) | ||
| 193 | file = dir.normalize(file) | ||
| 194 | local result | ||
| 195 | local tmpname = 'tmpluarockstestwritable.deleteme' | ||
| 196 | if fs.is_dir(file) then | ||
| 197 | local file2 = dir.path(file, tmpname) | ||
| 198 | local fh = io.open(file2, 'wb') | ||
| 199 | result = fh ~= nil | ||
| 200 | if fh then fh:close() end | ||
| 201 | if result then | ||
| 202 | -- the above test might give a false positive when writing to | ||
| 203 | -- c:\program files\ because of VirtualStore redirection on Vista and up | ||
| 204 | -- So check whether it's really there | ||
| 205 | result = fs.exists(file2) | ||
| 206 | end | ||
| 207 | os.remove(file2) | ||
| 208 | else | ||
| 209 | local fh = io.open(file, 'r+b') | ||
| 210 | result = fh ~= nil | ||
| 211 | if fh then fh:close() end | ||
| 212 | end | ||
| 213 | return result | ||
| 214 | end | ||
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua index 979aaff4..0ec46314 100644 --- a/src/luarocks/fs/win32/tools.lua +++ b/src/luarocks/fs/win32/tools.lua | |||
| @@ -12,10 +12,6 @@ local dir_stack = {} | |||
| 12 | 12 | ||
| 13 | local vars = cfg.variables | 13 | local vars = cfg.variables |
| 14 | 14 | ||
| 15 | local function pack(...) | ||
| 16 | return { n = select("#", ...), ... } | ||
| 17 | end | ||
| 18 | |||
| 19 | --- Strip the last extension of a filename. | 15 | --- Strip the last extension of a filename. |
| 20 | -- Example: "foo.tar.gz" becomes "foo.tar". | 16 | -- Example: "foo.tar.gz" becomes "foo.tar". |
| 21 | -- If filename has no dots, returns it unchanged. | 17 | -- If filename has no dots, returns it unchanged. |
| @@ -60,16 +56,8 @@ end | |||
| 60 | -- otherwise. | 56 | -- otherwise. |
| 61 | function execute_string(cmd) | 57 | function execute_string(cmd) |
| 62 | cmd = command_at(fs.current_dir(), cmd) | 58 | cmd = command_at(fs.current_dir(), cmd) |
| 63 | if cfg.verbose then print("Executing: "..tostring(cmd)) end | 59 | local code = os.execute(cmd) |
| 64 | local code = pack(os.execute(cmd)) | 60 | if code == 0 or code == true then |
| 65 | if cfg.verbose then | ||
| 66 | print("Results: "..tostring(code.n)) | ||
| 67 | for i = 1,code.n do | ||
| 68 | print(" "..tostring(i).." ("..type(code[i]).."): "..tostring(code[i])) | ||
| 69 | end | ||
| 70 | print() | ||
| 71 | end | ||
| 72 | if code[1] == 0 or code[1] == true then | ||
| 73 | return true | 61 | return true |
| 74 | else | 62 | else |
| 75 | return false | 63 | return false |
| @@ -112,7 +100,7 @@ end | |||
| 112 | function make_dir(directory) | 100 | function make_dir(directory) |
| 113 | assert(directory) | 101 | assert(directory) |
| 114 | directory = dir.normalize(directory) | 102 | directory = dir.normalize(directory) |
| 115 | fs.execute_quiet(vars.MKDIR.." -p ", directory) | 103 | fs.execute_quiet(fs.Q(vars.MKDIR).." -p ", directory) |
| 116 | if not fs.is_dir(directory) then | 104 | if not fs.is_dir(directory) then |
| 117 | return false, "failed making directory "..directory | 105 | return false, "failed making directory "..directory |
| 118 | end | 106 | end |
| @@ -125,7 +113,7 @@ end | |||
| 125 | -- @param directory string: pathname of directory to remove. | 113 | -- @param directory string: pathname of directory to remove. |
| 126 | function remove_dir_if_empty(directory) | 114 | function remove_dir_if_empty(directory) |
| 127 | assert(directory) | 115 | assert(directory) |
| 128 | fs.execute_quiet(vars.RMDIR, directory) | 116 | fs.execute_quiet(fs.Q(vars.RMDIR), directory) |
| 129 | end | 117 | end |
| 130 | 118 | ||
| 131 | --- Remove a directory if it is empty. | 119 | --- Remove a directory if it is empty. |
| @@ -134,7 +122,7 @@ end | |||
| 134 | -- @param directory string: pathname of directory to remove. | 122 | -- @param directory string: pathname of directory to remove. |
| 135 | function remove_dir_tree_if_empty(directory) | 123 | function remove_dir_tree_if_empty(directory) |
| 136 | assert(directory) | 124 | assert(directory) |
| 137 | fs.execute_quiet(vars.RMDIR, directory) | 125 | fs.execute_quiet(fs.Q(vars.RMDIR), directory) |
| 138 | end | 126 | end |
| 139 | 127 | ||
| 140 | --- Copy a file. | 128 | --- Copy a file. |
| @@ -145,7 +133,7 @@ end | |||
| 145 | function copy(src, dest) | 133 | function copy(src, dest) |
| 146 | assert(src and dest) | 134 | assert(src and dest) |
| 147 | if dest:match("[/\\]$") then dest = dest:sub(1, -2) end | 135 | if dest:match("[/\\]$") then dest = dest:sub(1, -2) end |
| 148 | local ok = fs.execute(vars.CP, src, dest) | 136 | local ok = fs.execute(fs.Q(vars.CP), src, dest) |
| 149 | if ok then | 137 | if ok then |
| 150 | return true | 138 | return true |
| 151 | else | 139 | else |
| @@ -160,7 +148,7 @@ end | |||
| 160 | -- plus an error message. | 148 | -- plus an error message. |
| 161 | function copy_contents(src, dest) | 149 | function copy_contents(src, dest) |
| 162 | assert(src and dest) | 150 | assert(src and dest) |
| 163 | if fs.execute_quiet(vars.CP.." -dR "..src.."\\*.* "..fs.Q(dest)) then | 151 | if fs.execute_quiet(fs.Q(vars.CP).." -dR "..src.."\\*.* "..fs.Q(dest)) then |
| 164 | return true | 152 | return true |
| 165 | else | 153 | else |
| 166 | return false, "Failed copying "..src.." to "..dest | 154 | return false, "Failed copying "..src.." to "..dest |
| @@ -191,7 +179,7 @@ function list_dir(at) | |||
| 191 | return {} | 179 | return {} |
| 192 | end | 180 | end |
| 193 | local result = {} | 181 | local result = {} |
| 194 | local pipe = io.popen(command_at(at, vars.LS)) | 182 | local pipe = io.popen(command_at(at, fs.Q(vars.LS))) |
| 195 | for file in pipe:lines() do | 183 | for file in pipe:lines() do |
| 196 | table.insert(result, file) | 184 | table.insert(result, file) |
| 197 | end | 185 | end |
| @@ -214,7 +202,7 @@ function find(at) | |||
| 214 | return {} | 202 | return {} |
| 215 | end | 203 | end |
| 216 | local result = {} | 204 | local result = {} |
| 217 | local pipe = io.popen(command_at(at, vars.FIND.." 2> NUL")) | 205 | local pipe = io.popen(command_at(at, fs.Q(vars.FIND).." 2> NUL")) |
| 218 | for file in pipe:lines() do | 206 | for file in pipe:lines() do |
| 219 | -- Windows find is a bit different | 207 | -- Windows find is a bit different |
| 220 | local first_two = file:sub(1,2) | 208 | local first_two = file:sub(1,2) |
| @@ -233,7 +221,7 @@ end | |||
| 233 | -- additional arguments. | 221 | -- additional arguments. |
| 234 | -- @return boolean: true on success, false on failure. | 222 | -- @return boolean: true on success, false on failure. |
| 235 | function zip(zipfile, ...) | 223 | function zip(zipfile, ...) |
| 236 | return fs.execute_quiet(vars.SEVENZ.." -aoa a -tzip", zipfile, ...) | 224 | return fs.execute_quiet(fs.Q(vars.SEVENZ).." -aoa a -tzip", zipfile, ...) |
| 237 | end | 225 | end |
| 238 | 226 | ||
| 239 | --- Uncompress files from a .zip archive. | 227 | --- Uncompress files from a .zip archive. |
| @@ -241,7 +229,7 @@ end | |||
| 241 | -- @return boolean: true on success, false on failure. | 229 | -- @return boolean: true on success, false on failure. |
| 242 | function unzip(zipfile) | 230 | function unzip(zipfile) |
| 243 | assert(zipfile) | 231 | assert(zipfile) |
| 244 | return fs.execute_quiet(vars.SEVENZ.." -aoa x", zipfile) | 232 | return fs.execute_quiet(fs.Q(vars.SEVENZ).." -aoa x", zipfile) |
| 245 | end | 233 | end |
| 246 | 234 | ||
| 247 | --- Test is pathname is a directory. | 235 | --- Test is pathname is a directory. |
| @@ -257,7 +245,7 @@ end | |||
| 257 | -- @return boolean: true if it is a regular file, false otherwise. | 245 | -- @return boolean: true if it is a regular file, false otherwise. |
| 258 | function is_file(file) | 246 | function is_file(file) |
| 259 | assert(file) | 247 | assert(file) |
| 260 | return fs.execute(vars.TEST.." -f", file) | 248 | return fs.execute(fs.Q(vars.TEST).." -f", file) |
| 261 | end | 249 | end |
| 262 | 250 | ||
| 263 | --- Download a remote file. | 251 | --- Download a remote file. |
| @@ -276,7 +264,7 @@ function download(url, filename, cache) | |||
| 276 | 264 | ||
| 277 | local ok | 265 | local ok |
| 278 | if cfg.downloader == "wget" then | 266 | if cfg.downloader == "wget" then |
| 279 | local wget_cmd = vars.WGET.." --no-check-certificate --no-cache --user-agent=\""..cfg.user_agent.." via wget\" --quiet " | 267 | local wget_cmd = fs.Q(vars.WGET).." --no-check-certificate --no-cache --user-agent=\""..cfg.user_agent.." via wget\" --quiet " |
| 280 | if cache then | 268 | if cache then |
| 281 | -- --timestamping is incompatible with --output-document, | 269 | -- --timestamping is incompatible with --output-document, |
| 282 | -- but that's not a problem for our use cases. | 270 | -- but that's not a problem for our use cases. |
| @@ -289,7 +277,7 @@ function download(url, filename, cache) | |||
| 289 | ok = fs.execute(wget_cmd..fs.Q(url).." 2> NUL 1> NUL") | 277 | ok = fs.execute(wget_cmd..fs.Q(url).." 2> NUL 1> NUL") |
| 290 | end | 278 | end |
| 291 | elseif cfg.downloader == "curl" then | 279 | elseif cfg.downloader == "curl" then |
| 292 | ok = fs.execute_string(vars.CURL.." -L --user-agent \""..cfg.user_agent.." via curl\" "..fs.Q(url).." 2> NUL 1> "..fs.Q(filename)) | 280 | ok = fs.execute_string(fs.Q(vars.CURL).." -L --user-agent \""..cfg.user_agent.." via curl\" "..fs.Q(url).." 2> NUL 1> "..fs.Q(filename)) |
| 293 | end | 281 | end |
| 294 | if ok then | 282 | if ok then |
| 295 | return true, filename | 283 | return true, filename |
| @@ -302,7 +290,7 @@ end | |||
| 302 | -- @param archive string: Filename of archive. | 290 | -- @param archive string: Filename of archive. |
| 303 | -- @return boolean : success status | 291 | -- @return boolean : success status |
| 304 | local function gunzip(archive) | 292 | local function gunzip(archive) |
| 305 | return fs.execute_quiet(vars.SEVENZ.." -aoa x", archive) | 293 | return fs.execute_quiet(fs.Q(vars.SEVENZ).." -aoa x", archive) |
| 306 | end | 294 | end |
| 307 | 295 | ||
| 308 | --- Unpack an archive. | 296 | --- Unpack an archive. |
| @@ -314,7 +302,7 @@ function unpack_archive(archive) | |||
| 314 | assert(type(archive) == "string") | 302 | assert(type(archive) == "string") |
| 315 | 303 | ||
| 316 | local ok | 304 | local ok |
| 317 | local sevenzx = vars.SEVENZ.." -aoa x" | 305 | local sevenzx = fs.Q(vars.SEVENZ).." -aoa x" |
| 318 | if archive:match("%.tar%.gz$") then | 306 | if archive:match("%.tar%.gz$") then |
| 319 | ok = gunzip(archive) | 307 | ok = gunzip(archive) |
| 320 | if ok then | 308 | if ok then |
| @@ -346,22 +334,25 @@ function unpack_archive(archive) | |||
| 346 | end | 334 | end |
| 347 | 335 | ||
| 348 | local md5_cmd = { | 336 | local md5_cmd = { |
| 349 | md5sum = vars.MD5SUM, | 337 | md5sum = fs.Q(vars.MD5SUM), |
| 350 | openssl = vars.OPENSSL.." md5", | 338 | openssl = fs.Q(vars.OPENSSL).." md5", |
| 351 | md5 = vars.MD5, | 339 | md5 = fs.Q(vars.MD5), |
| 352 | } | 340 | } |
| 353 | 341 | ||
| 354 | --- Get the MD5 checksum for a file. | 342 | --- Get the MD5 checksum for a file. |
| 355 | -- @param file string: The file to be computed. | 343 | -- @param file string: The file to be computed. |
| 356 | -- @return string: The MD5 checksum | 344 | -- @return string: The MD5 checksum or nil + message |
| 357 | function get_md5(file) | 345 | function get_md5(file) |
| 358 | local cmd = md5_cmd[cfg.md5checker] | 346 | local cmd = md5_cmd[cfg.md5checker] |
| 359 | if not cmd then return nil end | 347 | if not cmd then return nil end |
| 360 | local pipe = io.popen(cmd.." "..fs.absolute_name(file)) | 348 | local pipe = io.popen(cmd.." "..fs.Q(fs.absolute_name(file))) |
| 361 | local computed = pipe:read("*a") | 349 | local computed = pipe:read("*a") |
| 362 | pipe:close() | 350 | pipe:close() |
| 363 | if not computed then return nil end | 351 | if computed then |
| 364 | return computed:match("("..("%x"):rep(32)..")") | 352 | computed = computed:match("("..("%x"):rep(32)..")") |
| 353 | end | ||
| 354 | if computed then return computed end | ||
| 355 | return nil, "Failed to compute MD5 hash for file "..tostring(fs.absolute_name(file)) | ||
| 365 | end | 356 | end |
| 366 | 357 | ||
| 367 | --- Test for existance of a file. | 358 | --- Test for existance of a file. |
