From 370a2943c09e70154862f382fe3de7f486a4a1c6 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Wed, 13 Nov 2013 09:33:10 +0100 Subject: fixes LR install in location with spaces, quoting LR commands NOTE: seems to be broken now, bug not found yet --- src/luarocks/fs.lua | 19 +++++++++++++++++++ src/luarocks/fs/lua.lua | 8 ++++++-- src/luarocks/fs/win32/tools.lua | 36 ++++++++++++++++++------------------ 3 files changed, 43 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/luarocks/fs.lua b/src/luarocks/fs.lua index 467b1943..e002c7ba 100644 --- a/src/luarocks/fs.lua +++ b/src/luarocks/fs.lua @@ -38,3 +38,22 @@ load_fns(fs_lua) local ok, fs_plat_tools = pcall(require, "luarocks.fs."..loaded_platform..".tools") if ok and fs_plat_tools then load_fns(fs_plat_tools) end +-- uncomment below for further debugging than 'verbose=true' in config file +-- code below will also catch commands outside of fs.execute() +-- especially uses of io.popen(). +--[[ +old_exec = os.execute +os.execute = function(cmd) + print("os.execute: ", cmd) + return old_exec(cmd) +end +old_popen = io.popen +io.popen = function(one, two) + if two == nil then + print("io.popen: ", one) + else + print("io.popen: ", one, "Mode:", two) + end + return old_popen(one, two) +end +--]] diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index d477d88f..51cbee03 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua @@ -108,12 +108,16 @@ end -- The command is executed in the current directory in the dir stack. -- @param command string: The command to be executed. No quoting/escaping -- is applied. --- @param ... Strings containing additional arguments, which are quoted. +-- @param ... Strings containing additional arguments, which will be quoted. -- @return boolean: true if command succeeds (status code 0), false -- otherwise. function execute_quiet(command, ...) assert(type(command) == "string") - return fs.execute_string(fs.quiet(quote_args(command, ...))) + if cfg.verbose then + return fs.execute_string(quote_args(command, ...)) + else + return fs.execute_string(fs.quiet(quote_args(command, ...))) + end end --- Check the MD5 checksum for a file. diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua index 979aaff4..9aa76851 100644 --- a/src/luarocks/fs/win32/tools.lua +++ b/src/luarocks/fs/win32/tools.lua @@ -112,7 +112,7 @@ end function make_dir(directory) assert(directory) directory = dir.normalize(directory) - fs.execute_quiet(vars.MKDIR.." -p ", directory) + fs.execute_quiet(fs.Q(vars.MKDIR).." -p ", directory) if not fs.is_dir(directory) then return false, "failed making directory "..directory end @@ -125,7 +125,7 @@ end -- @param directory string: pathname of directory to remove. function remove_dir_if_empty(directory) assert(directory) - fs.execute_quiet(vars.RMDIR, directory) + fs.execute_quiet(fs.Q(vars.RMDIR), directory) end --- Remove a directory if it is empty. @@ -134,7 +134,7 @@ end -- @param directory string: pathname of directory to remove. function remove_dir_tree_if_empty(directory) assert(directory) - fs.execute_quiet(vars.RMDIR, directory) + fs.execute_quiet(fs.Q(vars.RMDIR), directory) end --- Copy a file. @@ -145,7 +145,7 @@ end function copy(src, dest) assert(src and dest) if dest:match("[/\\]$") then dest = dest:sub(1, -2) end - local ok = fs.execute(vars.CP, src, dest) + local ok = fs.execute(fs.Q(vars.CP), src, dest) if ok then return true else @@ -160,7 +160,7 @@ end -- plus an error message. function copy_contents(src, dest) assert(src and dest) - if fs.execute_quiet(vars.CP.." -dR "..src.."\\*.* "..fs.Q(dest)) then + if fs.execute_quiet(fs.Q(vars.CP).." -dR "..src.."\\*.* "..fs.Q(dest)) then return true else return false, "Failed copying "..src.." to "..dest @@ -191,7 +191,7 @@ function list_dir(at) return {} end local result = {} - local pipe = io.popen(command_at(at, vars.LS)) + local pipe = io.popen(command_at(at, fs.Q(vars.LS))) for file in pipe:lines() do table.insert(result, file) end @@ -214,7 +214,7 @@ function find(at) return {} end local result = {} - local pipe = io.popen(command_at(at, vars.FIND.." 2> NUL")) + local pipe = io.popen(command_at(at, fs.Q(vars.FIND).." 2> NUL")) for file in pipe:lines() do -- Windows find is a bit different local first_two = file:sub(1,2) @@ -233,7 +233,7 @@ end -- additional arguments. -- @return boolean: true on success, false on failure. function zip(zipfile, ...) - return fs.execute_quiet(vars.SEVENZ.." -aoa a -tzip", zipfile, ...) + return fs.execute_quiet(fs.Q(vars.SEVENZ).." -aoa a -tzip", zipfile, ...) end --- Uncompress files from a .zip archive. @@ -241,7 +241,7 @@ end -- @return boolean: true on success, false on failure. function unzip(zipfile) assert(zipfile) - return fs.execute_quiet(vars.SEVENZ.." -aoa x", zipfile) + return fs.execute_quiet(fs.Q(vars.SEVENZ).." -aoa x", zipfile) end --- Test is pathname is a directory. @@ -257,7 +257,7 @@ end -- @return boolean: true if it is a regular file, false otherwise. function is_file(file) assert(file) - return fs.execute(vars.TEST.." -f", file) + return fs.execute(fs.Q(vars.TEST).." -f", file) end --- Download a remote file. @@ -276,7 +276,7 @@ function download(url, filename, cache) local ok if cfg.downloader == "wget" then - local wget_cmd = vars.WGET.." --no-check-certificate --no-cache --user-agent=\""..cfg.user_agent.." via wget\" --quiet " + local wget_cmd = fs.Q(vars.WGET).." --no-check-certificate --no-cache --user-agent=\""..cfg.user_agent.." via wget\" --quiet " if cache then -- --timestamping is incompatible with --output-document, -- but that's not a problem for our use cases. @@ -289,7 +289,7 @@ function download(url, filename, cache) ok = fs.execute(wget_cmd..fs.Q(url).." 2> NUL 1> NUL") end elseif cfg.downloader == "curl" then - ok = fs.execute_string(vars.CURL.." -L --user-agent \""..cfg.user_agent.." via curl\" "..fs.Q(url).." 2> NUL 1> "..fs.Q(filename)) + 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)) end if ok then return true, filename @@ -302,7 +302,7 @@ end -- @param archive string: Filename of archive. -- @return boolean : success status local function gunzip(archive) - return fs.execute_quiet(vars.SEVENZ.." -aoa x", archive) + return fs.execute_quiet(fs.Q(vars.SEVENZ).." -aoa x", archive) end --- Unpack an archive. @@ -314,7 +314,7 @@ function unpack_archive(archive) assert(type(archive) == "string") local ok - local sevenzx = vars.SEVENZ.." -aoa x" + local sevenzx = fs.Q(vars.SEVENZ).." -aoa x" if archive:match("%.tar%.gz$") then ok = gunzip(archive) if ok then @@ -346,9 +346,9 @@ function unpack_archive(archive) end local md5_cmd = { - md5sum = vars.MD5SUM, - openssl = vars.OPENSSL.." md5", - md5 = vars.MD5, + md5sum = fs.Q(vars.MD5SUM), + openssl = fs.Q(vars.OPENSSL).." md5", + md5 = fs.Q(vars.MD5), } --- Get the MD5 checksum for a file. @@ -357,7 +357,7 @@ local md5_cmd = { 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 pipe = io.popen(cmd.." "..fs.Q(fs.absolute_name(file))) local computed = pipe:read("*a") pipe:close() if not computed then return nil end -- cgit v1.2.3-55-g6feb