From ed96305bc55cd27b7efc191724f29786a7a34026 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sun, 28 Dec 2025 19:22:31 -0300 Subject: fs: remove external-tool-based modules --- src/luarocks/fs/tools.lua | 222 ------------------- src/luarocks/fs/unix/tools.lua | 365 -------------------------------- src/luarocks/fs/win32/tools.lua | 331 ----------------------------- vendor/lua-zlib/lua-zlib-1.1-0.rockspec | 42 ---- vendor/lua-zlib/lua-zlib-1.2-0.rockspec | 42 ++++ 5 files changed, 42 insertions(+), 960 deletions(-) delete mode 100644 src/luarocks/fs/tools.lua delete mode 100644 src/luarocks/fs/unix/tools.lua delete mode 100644 src/luarocks/fs/win32/tools.lua delete mode 100644 vendor/lua-zlib/lua-zlib-1.1-0.rockspec create mode 100644 vendor/lua-zlib/lua-zlib-1.2-0.rockspec diff --git a/src/luarocks/fs/tools.lua b/src/luarocks/fs/tools.lua deleted file mode 100644 index b7d03759..00000000 --- a/src/luarocks/fs/tools.lua +++ /dev/null @@ -1,222 +0,0 @@ - ---- Common fs operations implemented with third-party tools. -local tools = {} - -local fs = require("luarocks.fs") -local dir = require("luarocks.dir") -local cfg = require("luarocks.core.cfg") - -local vars = setmetatable({}, { __index = function(_,k) return cfg.variables[k] end }) - -local dir_stack = {} - -do - local tool_cache = {} - - local tool_options = { - downloader = { - desc = "downloader", - { var = "WGET", name = "wget" }, - { var = "CURL", name = "curl" }, - }, - md5checker = { - desc = "MD5 checker", - { var = "MD5SUM", name = "md5sum" }, - { var = "OPENSSL", name = "openssl", cmdarg = "md5" }, - { var = "MD5", name = "md5" }, - }, - } - - function tools.which_tool(tooltype) - local tool = tool_cache[tooltype] - local names = {} - if not tool then - for _, opt in ipairs(tool_options[tooltype]) do - table.insert(names, opt.name) - if fs.is_tool_available(vars[opt.var], opt.name) then - tool = opt - tool_cache[tooltype] = opt - break - end - end - end - if not tool then - local tool_names = table.concat(names, ", ", 1, #names - 1) .. " or " .. names[#names] - return nil, "no " .. tool_options[tooltype].desc .. " tool available," .. " please install " .. tool_names .. " in your system" - end - return tool.name, vars[tool.var] .. (tool.cmdarg and " "..tool.cmdarg or "") - end -end - -local current_dir_with_cache -do - local cache_pwd - - current_dir_with_cache = function() - local current = cache_pwd - if not current then - local pipe = io.popen(fs.quiet_stderr(vars.PWD)) - current = pipe:read("*a"):gsub("^%s*", ""):gsub("%s*$", "") - pipe:close() - cache_pwd = current - end - for _, directory in ipairs(dir_stack) do - current = fs.absolute_name(directory, current) - end - return current, cache_pwd - end - - --- Obtain current directory. - -- Uses the module's internal directory stack. - -- @return string: the absolute pathname of the current directory. - function tools.current_dir() - return (current_dir_with_cache()) -- drop second return - end -end - ---- Change the current directory. --- Uses the module's internal directory stack. This does not have exact --- semantics of chdir, as it does not handle errors the same way, --- but works well for our purposes for now. --- @param directory string: The directory to switch to. --- @return boolean or (nil, string): true if successful, (nil, error message) if failed. -function tools.change_dir(directory) - assert(type(directory) == "string") - if fs.is_dir(directory) then - table.insert(dir_stack, directory) - return true - end - return nil, "directory not found: "..directory -end - ---- Change directory to root. --- Allows leaving a directory (e.g. for deleting it) in --- a crossplatform way. -function tools.change_dir_to_root() - local curr_dir = fs.current_dir() - if not curr_dir or not fs.is_dir(curr_dir) then - return false - end - table.insert(dir_stack, "/") - return true -end - ---- Change working directory to the previous in the directory stack. -function tools.pop_dir() - local directory = table.remove(dir_stack) - return directory ~= nil -end - ---- Run the given command. --- The command is executed in the current directory in the directory stack. --- @param cmd string: No quoting/escaping is applied to the command. --- @return boolean: true if command succeeds (status code 0), false --- otherwise. -function tools.execute_string(cmd) - local current, cache_pwd = current_dir_with_cache() - if not current then return false end - if current ~= cache_pwd then - cmd = fs.command_at(current, cmd) - end - local code = os.execute(cmd) - if code == 0 or code == true then - return true - else - return false - end -end - ---- Internal implementation function for fs.dir. --- Yields a filename on each iteration. --- @param at string: directory to list --- @return nil -function tools.dir_iterator(at) - local pipe = io.popen(fs.command_at(at, vars.LS, true)) - for file in pipe:lines() do - if file ~= "." and file ~= ".." then - coroutine.yield(file) - end - end - pipe:close() -end - ---- Download a remote file. --- @param url string: URL to be fetched. --- @param filename string or nil: this function attempts to detect the --- resulting local filename of the remote file as the basename of the URL; --- if that is not correct (due to a redirection, for example), the local --- filename can be given explicitly as this second argument. --- @param cache boolean: compare remote timestamps via HTTP HEAD prior to --- re-downloading the file. --- @return (string, string, string): filename on success, --- false and the error message and code on failure. -function tools.use_downloader(url, filename, cache) - assert(type(url) == "string") - assert(type(filename) == "string" or not filename) - - filename = fs.absolute_name(filename or dir.base_name(url)) - - local downloader, err = fs.which_tool("downloader") - if not downloader then - return nil, err, "downloader" - end - - local ok = false - if downloader == "wget" then - local wget_cmd = vars.WGET.." "..vars.WGETNOCERTFLAG.." --no-cache --user-agent=\""..cfg.user_agent.." via wget\" --quiet " - if cfg.connection_timeout and cfg.connection_timeout > 0 then - wget_cmd = wget_cmd .. "--timeout="..tostring(cfg.connection_timeout).." --tries=1 " - end - if cache then - -- --timestamping is incompatible with --output-document, - -- but that's not a problem for our use cases. - fs.delete(filename .. ".unixtime") - fs.change_dir(dir.dir_name(filename)) - ok = fs.execute_quiet(wget_cmd.." --timestamping ", url) - fs.pop_dir() - elseif filename then - ok = fs.execute_quiet(wget_cmd.." --output-document ", filename, url) - else - ok = fs.execute_quiet(wget_cmd, url) - end - elseif downloader == "curl" then - local curl_cmd = vars.CURL.." "..vars.CURLNOCERTFLAG.." -f -L --user-agent \""..cfg.user_agent.." via curl\" " - if cfg.connection_timeout and cfg.connection_timeout > 0 then - curl_cmd = curl_cmd .. "--connect-timeout "..tostring(cfg.connection_timeout).." " - end - if cache then - curl_cmd = curl_cmd .. " -R -z \"" .. filename .. "\" " - end - ok = fs.execute_string(fs.quiet_stderr(curl_cmd..fs.Q(url).." --output "..fs.Q(filename))) - end - if ok then - return filename - else - os.remove(filename) - return nil, "failed downloading " .. url, "network" - end -end - ---- Get the MD5 checksum for a file. --- @param file string: The file to be computed. --- @return string: The MD5 checksum or nil + message -function tools.get_md5(file) - local ok, md5checker = fs.which_tool("md5checker") - if not ok then - return false, md5checker - end - - local pipe = io.popen(md5checker.." "..fs.Q(fs.absolute_name(file))) - local computed = pipe:read("*l") - pipe:close() - if computed then - computed = computed:match("("..("%x"):rep(32)..")") - end - if computed then - return computed - else - return nil, "Failed to compute MD5 hash for file "..tostring(fs.absolute_name(file)) - end -end - -return tools diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua deleted file mode 100644 index 2127aed6..00000000 --- a/src/luarocks/fs/unix/tools.lua +++ /dev/null @@ -1,365 +0,0 @@ - ---- fs operations implemented with third-party tools for Unix platform abstractions. -local tools = {} - -local fs = require("luarocks.fs") -local dir = require("luarocks.dir") -local cfg = require("luarocks.core.cfg") - -local vars = setmetatable({}, { __index = function(_,k) return cfg.variables[k] end }) - ---- Adds prefix to command to make it run from a directory. --- @param directory string: Path to a directory. --- @param cmd string: A command-line string. --- @return string: The command-line with prefix. -function tools.command_at(directory, cmd) - return "cd " .. fs.Q(fs.absolute_name(directory)) .. " && " .. cmd -end - ---- Create a directory if it does not already exist. --- If any of the higher levels in the path name does not exist --- too, they are created as well. --- @param directory string: pathname of directory to create. --- @return boolean: true on success, false on failure. -function tools.make_dir(directory) - assert(directory) - local ok, err = fs.execute(vars.MKDIR.." -p", directory) - if not ok then - err = "failed making directory "..directory - end - return ok, err -end - ---- Remove a directory if it is empty. --- Does not return errors (for example, if directory is not empty or --- if already does not exist) --- @param directory string: pathname of directory to remove. -function tools.remove_dir_if_empty(directory) - assert(directory) - fs.execute_quiet(vars.RMDIR, directory) -end - ---- Remove a directory if it is empty. --- Does not return errors (for example, if directory is not empty or --- if already does not exist) --- @param directory string: pathname of directory to remove. -function tools.remove_dir_tree_if_empty(directory) - assert(directory) - fs.execute_quiet(vars.RMDIR, "-p", directory) -end - ---- Copy a file. --- @param src string: Pathname of source --- @param dest string: Pathname of destination --- @param perm string ("read" or "exec") or nil: Permissions for destination --- file or nil to use the source permissions --- @return boolean or (boolean, string): true on success, false on failure, --- plus an error message. -function tools.copy(src, dest, perm) - assert(src and dest) - if fs.execute(vars.CP, src, dest) then - if perm then - if fs.is_dir(dest) then - dest = dir.path(dest, dir.base_name(src)) - end - if fs.set_permissions(dest, perm, "all") then - return true - else - return false, "Failed setting permissions of "..dest - end - end - return true - else - return false, "Failed copying "..src.." to "..dest - end -end - ---- Recursively copy the contents of a directory. --- @param src string: Pathname of source --- @param dest string: Pathname of destination --- @return boolean or (boolean, string): true on success, false on failure, --- plus an error message. -function tools.copy_contents(src, dest) - assert(src and dest) - if not fs.is_dir(src) then - return false, src .. " is not a directory" - end - if fs.make_dir(dest) and fs.execute_quiet(vars.CP.." -pPR "..fs.Q(src).."/* "..fs.Q(dest)) then - return true - else - return false, "Failed copying "..src.." to "..dest - end -end ---- Delete a file or a directory and all its contents. --- For safety, this only accepts absolute paths. --- @param pathname string: Pathname of source --- @return true on success, nil and an error on failure -function tools.delete(pathname) - assert(pathname) - assert(pathname:sub(1,1) == "/") - if fs.execute_quiet(vars.RM, "-rf", pathname) then - return true - else - return nil, "failed deleting " .. pathname - end -end - ---- Recursively scan the contents of a directory. --- @param at string or nil: directory to scan (will be the current --- directory if none is given). --- @return table: an array of strings with the filenames representing --- the contents of a directory. -function tools.find(at) - assert(type(at) == "string" or not at) - if not at then - at = fs.current_dir() - end - if not fs.is_dir(at) then - return {} - end - local result = {} - local pipe = io.popen(fs.command_at(at, fs.quiet_stderr(vars.FIND.." *"))) - for file in pipe:lines() do - table.insert(result, file) - end - pipe:close() - return result -end - ---- Compress files in a .zip archive. --- @param zipfile string: pathname of .zip archive to be created. --- @param ... Filenames to be stored in the archive are given as --- additional arguments. --- @return boolean: true on success, nil and error message on failure. -function tools.zip(zipfile, ...) - local ok, err = fs.is_tool_available(vars.ZIP, "zip") - if not ok then - return nil, err - end - if fs.execute_quiet(vars.ZIP.." -r", zipfile, ...) then - return true - else - return nil, "failed compressing " .. zipfile - end -end - ---- Uncompress files from a .zip archive. --- @param zipfile string: pathname of .zip archive to be extracted. --- @return boolean: true on success, nil and error message on failure. -function tools.unzip(zipfile) - assert(zipfile) - local ok, err = fs.is_tool_available(vars.UNZIP, "unzip") - if not ok then - return nil, err - end - if fs.execute_quiet(vars.UNZIP, zipfile) then - return true - else - return nil, "failed extracting " .. zipfile - end -end - -local function uncompress(default_ext, program, infile, outfile) - assert(type(infile) == "string") - assert(outfile == nil or type(outfile) == "string") - if not outfile then - outfile = infile:gsub("%."..default_ext.."$", "") - end - if fs.execute(fs.Q(program).." -c "..fs.Q(infile).." > "..fs.Q(outfile)) then - return true - else - return nil, "failed extracting " .. infile - end -end - ---- Uncompresses a .gz file. --- @param infile string: pathname of .gz file to be extracted. --- @param outfile string or nil: pathname of output file to be produced. --- If not given, name is derived from input file. --- @return boolean: true on success; nil and error message on failure. -function tools.gunzip(infile, outfile) - return uncompress("gz", "gunzip", infile, outfile) -end - ---- Uncompresses a .bz2 file. --- @param infile string: pathname of .bz2 file to be extracted. --- @param outfile string or nil: pathname of output file to be produced. --- If not given, name is derived from input file. --- @return boolean: true on success; nil and error message on failure. -function tools.bunzip2(infile, outfile) - return uncompress("bz2", "bunzip2", infile, outfile) -end - -do - local function rwx_to_octal(rwx) - return (rwx:match "r" and 4 or 0) - + (rwx:match "w" and 2 or 0) - + (rwx:match "x" and 1 or 0) - end - local umask_cache - function tools._unix_umask() - if umask_cache then - return umask_cache - end - local fd = assert(io.popen("umask -S")) - local umask = assert(fd:read("*a")) - fd:close() - local u, g, o = umask:match("u=([rwx]*),g=([rwx]*),o=([rwx]*)") - if not u then - error("invalid umask result") - end - umask_cache = string.format("%d%d%d", - 7 - rwx_to_octal(u), - 7 - rwx_to_octal(g), - 7 - rwx_to_octal(o)) - return umask_cache - end -end - ---- Set permissions for file or directory --- @param filename string: filename whose permissions are to be modified --- @param mode string ("read" or "exec"): permissions to set --- @param scope string ("user" or "all"): the user(s) to whom the permission applies --- @return boolean or (boolean, string): true on success, false on failure, --- plus an error message -function tools.set_permissions(filename, mode, scope) - assert(filename and mode and scope) - - local perms, err = fs._unix_mode_scope_to_perms(mode, scope) - if err then - return false, err - end - - return fs.execute(vars.CHMOD, perms, filename) -end - -function tools.browser(url) - return fs.execute(cfg.web_browser, url) -end - --- Set access and modification times for a file. --- @param filename File to set access and modification times for. --- @param time may be a string or number containing the format returned --- by os.time, or a table ready to be processed via os.time; if --- nil, current time is assumed. -function tools.set_time(file, time) - assert(time == nil or type(time) == "table" or type(time) == "number") - file = dir.normalize(file) - local flag = "" - if type(time) == "number" then - time = os.date("*t", time) - end - if type(time) == "table" then - flag = ("-t %04d%02d%02d%02d%02d.%02d"):format(time.year, time.month, time.day, time.hour, time.min, time.sec) - end - return fs.execute(vars.TOUCH .. " " .. flag, file) -end - ---- Create a temporary directory. --- @param name_pattern string: name pattern to use for avoiding conflicts --- when creating temporary directory. --- @return string or (nil, string): name of temporary directory or (nil, error message) on failure. -function tools.make_temp_dir(name_pattern) - assert(type(name_pattern) == "string") - name_pattern = dir.normalize(name_pattern) - - local template = (os.getenv("TMPDIR") or "/tmp") .. "/luarocks_" .. name_pattern:gsub("/", "_") .. "-XXXXXX" - local pipe = io.popen(vars.MKTEMP.." -d "..fs.Q(template)) - local dirname = pipe:read("*l") - pipe:close() - if dirname and dirname:match("^/") then - return dirname - end - return nil, "Failed to create temporary directory "..tostring(dirname) -end - ---- Test is file/directory exists --- @param file string: filename to test --- @return boolean: true if file exists, false otherwise. -function tools.exists(file) - assert(file) - return fs.execute(vars.TEST, "-e", file) -end - ---- Test is pathname is a directory. --- @param file string: pathname to test --- @return boolean: true if it is a directory, false otherwise. -function tools.is_dir(file) - assert(file) - return fs.execute(vars.TEST, "-d", file) -end - ---- Test is pathname is a regular file. --- @param file string: pathname to test --- @return boolean: true if it is a regular file, false otherwise. -function tools.is_file(file) - assert(file) - return fs.execute(vars.TEST, "-f", file) -end - -function tools.current_user() - local user = os.getenv("USER") - if user then - return user - end - local pd = io.popen("whoami", "r") - if not pd then - return "" - end - user = pd:read("*l") - pd:close() - return user -end - -function tools.is_superuser() - return fs.current_user() == "root" -end - -local lock_mt = { - __gc = function(lock) - fs.unlock_access(lock) - end -} - -function tools.lock_access(dirname, force) - local ok, err = fs.make_dir(dirname) - if not ok then - return nil, err - end - - local tempfile = dir.path(dirname, ".lock.tmp." .. tostring(math.random(100000000))) - - local fd, fderr = io.open(tempfile, "w") - if not fd then - return nil, "failed opening temp file " .. tempfile .. " for locking: " .. fderr - end - - local ok, werr = fd:write("lock file for " .. dirname) - if not ok then - return nil, "failed writing temp file " .. tempfile .. " for locking: " .. werr - end - - fd:close() - - local lockfile = dir.path(dirname, "lockfile.lfs") - - local force_flag = force and " -f" or "" - - if fs.execute(vars.LN .. force_flag, tempfile, lockfile) then - local lock = { - tempfile = tempfile, - lockfile = lockfile, - } - setmetatable(lock, lock_mt) - return lock - else - return nil, "File exists" -- same message as luafilesystem - end -end - -function tools.unlock_access(lock) - os.remove(lock.lockfile) - os.remove(lock.tempfile) -end - -return tools diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua deleted file mode 100644 index 56f04b19..00000000 --- a/src/luarocks/fs/win32/tools.lua +++ /dev/null @@ -1,331 +0,0 @@ - ---- fs operations implemented with third-party tools for Windows platform abstractions. --- Download http://unxutils.sourceforge.net/ for Windows GNU utilities --- used by this module. -local tools = {} - -local fs = require("luarocks.fs") -local dir = require("luarocks.dir") -local cfg = require("luarocks.core.cfg") - -local vars = setmetatable({}, { __index = function(_,k) return cfg.variables[k] end }) - -local dir_sep = package.config:sub(1, 1) - ---- Adds prefix to command to make it run from a directory. --- @param directory string: Path to a directory. --- @param cmd string: A command-line string. --- @param exit_on_error bool: Exits immediately if entering the directory failed. --- @return string: The command-line with prefix. -function tools.command_at(directory, cmd, exit_on_error) - local drive = directory:match("^([A-Za-z]:)") - local op = " & " - if exit_on_error then - op = " && " - end - local cmd_prefixed = "cd " .. fs.Q(directory) .. op .. cmd - if drive then - cmd_prefixed = drive .. " & " .. cmd_prefixed - end - return cmd_prefixed -end - ---- Create a directory if it does not already exist. --- If any of the higher levels in the path name does not exist --- too, they are created as well. --- @param directory string: pathname of directory to create. --- @return boolean: true on success, false on failure. -function tools.make_dir(directory) - assert(directory) - directory = dir.normalize(directory) - fs.execute_quiet(vars.MKDIR, directory) - if not fs.is_dir(directory) then - return false, "failed making directory "..directory - end - return true -end - ---- Remove a directory if it is empty. --- Does not return errors (for example, if directory is not empty or --- if already does not exist) --- @param directory string: pathname of directory to remove. -function tools.remove_dir_if_empty(directory) - assert(directory) - fs.execute_quiet(vars.RMDIR, directory) -end - ---- Remove a directory if it is empty. --- Does not return errors (for example, if directory is not empty or --- if already does not exist) --- @param directory string: pathname of directory to remove. -function tools.remove_dir_tree_if_empty(directory) - assert(directory) - while true do - fs.execute_quiet(vars.RMDIR, directory) - local parent = dir.dir_name(directory) - if parent ~= directory then - directory = parent - else - break - end - end -end - ---- Copy a file. --- @param src string: Pathname of source --- @param dest string: Pathname of destination --- @return boolean or (boolean, string): true on success, false on failure, --- plus an error message. -function tools.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) - if ok then - return true - else - return false, "Failed copying "..src.." to "..dest - end -end - ---- Recursively copy the contents of a directory. --- @param src string: Pathname of source --- @param dest string: Pathname of destination --- @return boolean or (boolean, string): true on success, false on failure, --- plus an error message. -function tools.copy_contents(src, dest) - assert(src and dest) - if not fs.is_dir(src) then - return false, src .. " is not a directory" - end - if fs.make_dir(dest) and fs.execute_quiet(vars.CP, "-dR", src.."\\*.*", dest) then - return true - else - return false, "Failed copying "..src.." to "..dest - end -end - ---- Delete a file or a directory and all its contents. --- For safety, this only accepts absolute paths. --- @param arg string: Pathname of source --- @return nil -function tools.delete(arg) - assert(arg) - assert(arg:match("^[a-zA-Z]?:?[\\/]")) - fs.execute_quiet("if exist "..fs.Q(arg.."\\*").." ( RMDIR /S /Q "..fs.Q(arg).." ) else ( DEL /Q /F "..fs.Q(arg).." )") -end - ---- Recursively scan the contents of a directory. --- @param at string or nil: directory to scan (will be the current --- directory if none is given). --- @return table: an array of strings with the filenames representing --- the contents of a directory. Paths are returned with forward slashes. -function tools.find(at) - assert(type(at) == "string" or not at) - if not at then - at = fs.current_dir() - end - if not fs.is_dir(at) then - return {} - end - local result = {} - local pipe = io.popen(fs.command_at(at, fs.quiet_stderr(vars.FIND), true)) - for file in pipe:lines() do - -- Windows find is a bit different - local file = file - local first_two = file:sub(1,2) - if first_two == ".\\" or first_two == "./" then file=file:sub(3) end - if file ~= "." then - table.insert(result, (file:gsub("[\\/]", dir_sep))) - end - end - pipe:close() - return result -end - ---- Compress files in a .zip archive. --- @param zipfile string: pathname of .zip archive to be created. --- @param ... Filenames to be stored in the archive are given as --- additional arguments. --- @return boolean: true on success, nil and error message on failure. -function tools.zip(zipfile, ...) - if fs.execute_quiet(vars.SEVENZ.." -aoa a -tzip", zipfile, ...) then - return true - else - return nil, "failed compressing " .. zipfile - end -end - ---- Uncompress files from a .zip archive. --- @param zipfile string: pathname of .zip archive to be extracted. --- @return boolean: true on success, nil and error message on failure. -function tools.unzip(zipfile) - assert(zipfile) - if fs.execute_quiet(vars.SEVENZ.." -aoa x", zipfile) then - return true - else - return nil, "failed extracting " .. zipfile - end -end - -local function sevenz(default_ext, infile, outfile) - assert(type(infile) == "string") - assert(outfile == nil or type(outfile) == "string") - - local dropext = infile:gsub("%."..default_ext.."$", "") - local outdir = dir.dir_name(dropext) - - infile = fs.absolute_name(infile) - - local cmdline = vars.SEVENZ.." -aoa -t* -o"..fs.Q(outdir).." x "..fs.Q(infile) - local ok, err = fs.execute_quiet(cmdline) - if not ok then - return nil, "failed extracting " .. infile - end - - if outfile then - outfile = fs.absolute_name(outfile) - dropext = fs.absolute_name(dropext) - ok, err = os.rename(dropext, outfile) - if not ok then - return nil, "failed creating new file " .. outfile - end - end - - return true -end - ---- Uncompresses a .gz file. --- @param infile string: pathname of .gz file to be extracted. --- @param outfile string or nil: pathname of output file to be produced. --- If not given, name is derived from input file. --- @return boolean: true on success; nil and error message on failure. -function tools.gunzip(infile, outfile) - return sevenz("gz", infile, outfile) -end - ---- Uncompresses a .bz2 file. --- @param infile string: pathname of .bz2 file to be extracted. --- @param outfile string or nil: pathname of output file to be produced. --- If not given, name is derived from input file. --- @return boolean: true on success; nil and error message on failure. -function tools.bunzip2(infile, outfile) - return sevenz("bz2", infile, outfile) -end - ---- Helper function for fs.set_permissions --- @return table: an array of all system users -local function get_system_users() - local exclude = { - [""] = true, - ["Name"] = true, - ["\128\164\172\168\173\168\225\226\224\160\226\174\224"] = true, -- Administrator in cp866 - ["Administrator"] = true, - } - local result = {} - local fd = assert(io.popen("wmic UserAccount get name")) - for user in fd:lines() do - local user = user:gsub("%s+$", "") - if not exclude[user] then - table.insert(result, user) - end - end - return result -end - ---- Set permissions for file or directory --- @param filename string: filename whose permissions are to be modified --- @param mode string ("read" or "exec"): permission to set --- @param scope string ("user" or "all"): the user(s) to whom the permission applies --- @return boolean or (boolean, string): true on success, false on failure, --- plus an error message -function tools.set_permissions(filename, mode, scope) - assert(filename and mode and scope) - - if scope == "user" then - local perms - if mode == "read" then - perms = "(R,W,M)" - elseif mode == "exec" then - perms = "(F)" - end - - local ok - -- Take ownership of the given file - ok = fs.execute_quiet("takeown /f " .. fs.Q(filename)) - if not ok then - return false, "Could not take ownership of the given file" - end - local username = os.getenv('USERNAME') - -- Grant the current user the proper rights - ok = fs.execute_quiet(vars.ICACLS .. " " .. fs.Q(filename) .. " /inheritance:d /grant:r " .. fs.Q(username) .. ":" .. perms) - if not ok then - return false, "Failed setting permission " .. mode .. " for " .. scope - end - -- Finally, remove all the other users from the ACL in order to deny them access to the file - for _, user in pairs(get_system_users()) do - if username ~= user then - local ok = fs.execute_quiet(vars.ICACLS .. " " .. fs.Q(filename) .. " /remove " .. fs.Q(user)) - if not ok then - return false, "Failed setting permission " .. mode .. " for " .. scope - end - end - end - elseif scope == "all" then - local my_perms, others_perms - if mode == "read" then - my_perms = "(R,W,M)" - others_perms = "(R)" - elseif mode == "exec" then - my_perms = "(F)" - others_perms = "(RX)" - end - - local ok - -- Grant permissions available to all users - ok = fs.execute_quiet(vars.ICACLS .. " " .. fs.Q(filename) .. " /inheritance:d /grant:r *S-1-1-0:" .. others_perms) - if not ok then - return false, "Failed setting permission " .. mode .. " for " .. scope - end - - -- Grant permissions available only to the current user - ok = fs.execute_quiet(vars.ICACLS .. " " .. fs.Q(filename) .. " /inheritance:d /grant \"%USERNAME%\":" .. my_perms) - - -- This may not be necessary if the above syntax is correct, - -- but I couldn't really test the extra quotes above, so if that - -- fails we try again with the syntax used in previous releases - -- just to be on the safe side - if not ok then - ok = fs.execute_quiet(vars.ICACLS .. " " .. fs.Q(filename) .. " /inheritance:d /grant %USERNAME%:" .. my_perms) - end - - if not ok then - return false, "Failed setting permission " .. mode .. " for " .. scope - end - end - - return true -end - -function tools.browser(url) - return fs.execute(cfg.web_browser..' "Starting docs..." '..fs.Q(url)) -end - --- Set access and modification times for a file. --- @param filename File to set access and modification times for. --- @param time may be a string or number containing the format returned --- by os.time, or a table ready to be processed via os.time; if --- nil, current time is assumed. -function tools.set_time(filename, time) - return true -- FIXME -end - -function tools.lock_access(dirname) - -- NYI - return {} -end - -function tools.unlock_access(lock) - -- NYI -end - -return tools diff --git a/vendor/lua-zlib/lua-zlib-1.1-0.rockspec b/vendor/lua-zlib/lua-zlib-1.1-0.rockspec deleted file mode 100644 index 7927d6ce..00000000 --- a/vendor/lua-zlib/lua-zlib-1.1-0.rockspec +++ /dev/null @@ -1,42 +0,0 @@ -package = "lua-zlib" -version = "1.2-0" -source = { - url = "git://github.com/brimworks/lua-zlib.git", - tag = "v1.2", -} -description = { - summary = "Simple streaming interface to zlib for Lua.", - detailed = [[ - Simple streaming interface to zlib for Lua. - Consists of two functions: inflate and deflate. - Both functions return "stream functions" (takes a buffer of input and returns a buffer of output). - This project is hosted on github. - ]], - homepage = "https://github.com/brimworks/lua-zlib", - license = "MIT" -} -dependencies = { - "lua >= 5.1, <= 5.3" -} -external_dependencies = { - ZLIB = { - header = "zlib.h" - } -} - -build = { - type = "builtin", - modules = { - zlib = { - sources = { "lua_zlib.c" }, - libraries = { "z" }, - defines = { "LZLIB_COMPAT" }, - incdirs = { "$(ZLIB_INCDIR)" }, - } - }, - platforms = { - windows = { modules = { zlib = { libraries = { - "$(ZLIB_LIBDIR)/zlib" -- Must full path to `"zlib"`, or else will cause the `LINK : fatal error LNK1149` - } } } } - } -} diff --git a/vendor/lua-zlib/lua-zlib-1.2-0.rockspec b/vendor/lua-zlib/lua-zlib-1.2-0.rockspec new file mode 100644 index 00000000..7927d6ce --- /dev/null +++ b/vendor/lua-zlib/lua-zlib-1.2-0.rockspec @@ -0,0 +1,42 @@ +package = "lua-zlib" +version = "1.2-0" +source = { + url = "git://github.com/brimworks/lua-zlib.git", + tag = "v1.2", +} +description = { + summary = "Simple streaming interface to zlib for Lua.", + detailed = [[ + Simple streaming interface to zlib for Lua. + Consists of two functions: inflate and deflate. + Both functions return "stream functions" (takes a buffer of input and returns a buffer of output). + This project is hosted on github. + ]], + homepage = "https://github.com/brimworks/lua-zlib", + license = "MIT" +} +dependencies = { + "lua >= 5.1, <= 5.3" +} +external_dependencies = { + ZLIB = { + header = "zlib.h" + } +} + +build = { + type = "builtin", + modules = { + zlib = { + sources = { "lua_zlib.c" }, + libraries = { "z" }, + defines = { "LZLIB_COMPAT" }, + incdirs = { "$(ZLIB_INCDIR)" }, + } + }, + platforms = { + windows = { modules = { zlib = { libraries = { + "$(ZLIB_LIBDIR)/zlib" -- Must full path to `"zlib"`, or else will cause the `LINK : fatal error LNK1149` + } } } } + } +} -- cgit v1.2.3-55-g6feb