From 4724492df402089b0529c3ef7cb4fd240cbb5ed0 Mon Sep 17 00:00:00 2001
From: Hisham Muhammad <hisham@gobolinux.org>
Date: Sun, 14 Aug 2011 14:50:10 -0300
Subject: Abstract all external commands so they can be overriden via
 config.lua

---
 src/luarocks/add.lua            |  6 ++--
 src/luarocks/cache.lua          |  4 +--
 src/luarocks/cfg.lua            | 50 +++++++++++++++++++++++++---
 src/luarocks/fetch/cvs.lua      |  2 +-
 src/luarocks/fetch/git.lua      |  5 +--
 src/luarocks/fetch/sscm.lua     |  5 +--
 src/luarocks/fetch/svn.lua      |  3 +-
 src/luarocks/fs/unix/tools.lua  | 73 +++++++++++++++++------------------------
 src/luarocks/fs/win32/tools.lua | 57 +++++++++++++++++---------------
 9 files changed, 121 insertions(+), 84 deletions(-)

diff --git a/src/luarocks/add.lua b/src/luarocks/add.lua
index 92b5ac4b..6edfea35 100644
--- a/src/luarocks/add.lua
+++ b/src/luarocks/add.lua
@@ -81,12 +81,12 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server)
    local cmd
    if protocol == "rsync" then
       local srv, path = server_path:match("([^/]+)(/.+)")
-      cmd = "rsync --exclude=.git -Oavz -e ssh "..local_cache.."/ "..user.."@"..srv..":"..path.."/"
+      cmd = cfg.variables.RSYNC.." --exclude=.git -Oavz -e ssh "..local_cache.."/ "..user.."@"..srv..":"..path.."/"
    elseif upload_server and upload_server.sftp then
       local part1, part2 = upload_server.sftp:match("^([^/]*)/(.*)$")
-      cmd = "scp manifest index.html "..table.concat(files, " ").." "..user.."@"..part1..":/"..part2
+      cmd = cfg.variables.SCP.." manifest index.html "..table.concat(files, " ").." "..user.."@"..part1..":/"..part2
    else
-      cmd = "curl "..login_info.." -T '{manifest,index.html,"..table.concat(files, ",").."}' "..login_url
+      cmd = cfg.variables.CURL.." "..login_info.." -T '{manifest,index.html,"..table.concat(files, ",").."}' "..login_url
    end
 
    util.printout(cmd)
diff --git a/src/luarocks/cache.lua b/src/luarocks/cache.lua
index 692d3346..21185c10 100644
--- a/src/luarocks/cache.lua
+++ b/src/luarocks/cache.lua
@@ -71,12 +71,12 @@ function refresh_local_cache(server, url, user, password)
    local ok = false
    if protocol == "rsync" then
       local srv, path = server_path:match("([^/]+)(/.+)")
-      ok = fs.execute("rsync -avz -e ssh "..user.."@"..srv..":"..path.."/ "..local_cache.."/")
+      ok = fs.execute(cfg.variables.RSYNC.." -avz -e ssh "..user.."@"..srv..":"..path.."/ "..local_cache.."/")
    else 
       local login_info = ""
       if user then login_info = " --user="..user end
       if password then login_info = login_info .. " --password="..password end
-      ok = fs.execute("wget --no-cache -q -m -np -nd "..protocol.."://"..server_path..login_info)
+      ok = fs.execute(cfg.variables.WGET.." --no-cache -q -m -np -nd "..protocol.."://"..server_path..login_info)
    end
    if not ok then
       return nil, "Failed downloading cache."
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua
index ace0dbf1..1abe39cb 100644
--- a/src/luarocks/cfg.lua
+++ b/src/luarocks/cfg.lua
@@ -145,7 +145,47 @@ local defaults = {
    downloader = config.LUAROCKS_DOWNLOADER or "wget",
    md5checker = config.LUAROCKS_MD5CHECKER or "md5sum",
 
-   variables = {},
+   variables = {
+      MAKE = "make",
+      CC = "cc",
+      LD = "ld",
+      
+      CVS = "cvs",
+      GIT = "git",
+      SSCM = "sscm",
+      SVN = "svn",
+      
+      RSYNC = "rsync",
+      WGET = "wget",
+      SCP = "scp",
+      CURL = "curl",
+      
+      PWD = "pwd",
+      MKDIR = "mkdir",
+      RMDIR = "rmdir",
+      CP = "cp",
+      LS = "ls",
+      RM = "rm",
+      FIND = "find",
+      TEST = "test",
+      CHMOD = "chmod",
+      PATCH = "patch",
+
+      ZIP = "zip",
+      UNZIP = "unzip",
+      GUNZIP = "gunzip",
+      BUNZIP2 = "bunzip2",
+      TAR = "tar",
+      
+      MD5SUM = "md5sum",
+      OPENSSL = "openssl",
+      MD5 = "md5",
+      STAT = "stat",
+      
+      SEVENZ = "7z",
+      
+      STATFLAG = "-c '%a'",
+   },
    
    external_deps_subdirs = {
       bin = "bin",
@@ -241,9 +281,6 @@ if detected.unix then
    defaults.variables.CFLAGS = "-O2"
    defaults.cmake_generator = "Unix Makefiles"
    defaults.platforms = { "unix" }
-   defaults.variables.MAKE = "make"
-   defaults.variables.CC = "cc"
-   defaults.variables.LD = "ld"
    defaults.variables.LIBFLAG = "-shared"
    defaults.external_deps_patterns = {
       bin = { "?" },
@@ -282,6 +319,10 @@ if detected.macosx then
    defaults.variables.LIBFLAG = "-bundle -undefined dynamic_lookup -all_load"
 end
 
+if detected.bsd then
+   defaults.variables.STATFLAG = "-f '%A'"
+end
+
 if detected.linux then
    defaults.arch = "linux-"..proc
    defaults.platforms = {"unix", "linux"}
@@ -302,6 +343,7 @@ end
 if detected.openbsd then
    defaults.arch = "openbsd-"..proc
    defaults.platforms = {"unix", "bsd", "openbsd"}
+   defaults.variables.STATFLAG = "-f '%Op'"
 end
 
 -- Expose some more values detected by LuaRocks for use by rockspec authors.
diff --git a/src/luarocks/fetch/cvs.lua b/src/luarocks/fetch/cvs.lua
index c2957c09..a622cdcb 100644
--- a/src/luarocks/fetch/cvs.lua
+++ b/src/luarocks/fetch/cvs.lua
@@ -19,7 +19,7 @@ function get_sources(rockspec, extract, dest_dir)
 
    local name_version = rockspec.name .. "-" .. rockspec.version
    local module = rockspec.source.module or dir.base_name(rockspec.source.url)
-   local command = {"cvs", "-d"..rockspec.source.pathname, "export", module}
+   local command = {rockspec.variables.CVS, "-d"..rockspec.source.pathname, "export", module}
    if rockspec.source.tag then
       table.insert(command, 4, "-r")
       table.insert(command, 5, rockspec.source.tag)
diff --git a/src/luarocks/fetch/git.lua b/src/luarocks/fetch/git.lua
index a3b763d6..7db74c26 100644
--- a/src/luarocks/fetch/git.lua
+++ b/src/luarocks/fetch/git.lua
@@ -17,15 +17,16 @@ function get_sources(rockspec, extract, dest_dir)
    assert(type(rockspec) == "table")
    assert(type(dest_dir) == "string" or not dest_dir)
 
+   local git_cmd = rockspec.variables.GIT
    local name_version = rockspec.name .. "-" .. rockspec.version
    local module = dir.base_name(rockspec.source.url)
    -- Strip off .git from base name if present
    module = module:gsub("%.git$", "")
-   local command = {"git", "clone", "--depth=1", rockspec.source.url, module}
+   local command = {git_cmd, "clone", "--depth=1", rockspec.source.url, module}
    local checkout_command
    local tag_or_branch = rockspec.source.tag or rockspec.source.branch
    if tag_or_branch then
-      checkout_command = {"git", "checkout", tag_or_branch}
+      checkout_command = {git_cmd, "checkout", tag_or_branch}
    end
    local store_dir
    if not dest_dir then
diff --git a/src/luarocks/fetch/sscm.lua b/src/luarocks/fetch/sscm.lua
index 539014c2..e52e8019 100644
--- a/src/luarocks/fetch/sscm.lua
+++ b/src/luarocks/fetch/sscm.lua
@@ -16,6 +16,7 @@ function get_sources(rockspec, extract, dest_dir)
    assert(type(rockspec) == "table")
    assert(type(dest_dir) == "string" or not dest_dir)
 
+   local sscm_cmd = rockspec.variables.SSCM
    local module = rockspec.source.module or dir.base_name(rockspec.source.url)
    local branch, repository = string.match(rockspec.source.pathname, "^([^/]*)/(.*)")
    if not branch or not repository then
@@ -23,7 +24,7 @@ function get_sources(rockspec, extract, dest_dir)
    end
    -- Search for working directory.
    local working_dir
-   local tmp = io.popen(string.format([[sscm property "/" -d -b%s -p%s]], branch, repository))
+   local tmp = io.popen(string.format(sscm_cmd..[[ property "/" -d -b%s -p%s]], branch, repository))
    for line in tmp:lines() do
       --%c because a chr(13) comes in the end.
       working_dir = string.match(line, "Working directory:[%s]*(.*)%c$")
@@ -33,7 +34,7 @@ function get_sources(rockspec, extract, dest_dir)
    if not working_dir then
       return nil, "Error retrieving working directory from SSCM."
    end
-   if not fs.execute([["sscm"]], "get", "*", "-e" , "-r", "-b"..branch, "-p"..repository, "-tmodify", "-wreplace") then
+   if not fs.execute(sscm_cmd, "get", "*", "-e" , "-r", "-b"..branch, "-p"..repository, "-tmodify", "-wreplace") then
       return nil, "Failed fetching files from SSCM."
    end
    -- FIXME: This function does not honor the dest_dir parameter.
diff --git a/src/luarocks/fetch/svn.lua b/src/luarocks/fetch/svn.lua
index 01ea6ba9..9d00ce5b 100644
--- a/src/luarocks/fetch/svn.lua
+++ b/src/luarocks/fetch/svn.lua
@@ -17,10 +17,11 @@ function get_sources(rockspec, extract, dest_dir)
    assert(type(rockspec) == "table")
    assert(type(dest_dir) == "string" or not dest_dir)
 
+   local svn_cmd = rockspec.variables.SVN
    local name_version = rockspec.name .. "-" .. rockspec.version
    local module = rockspec.source.module or dir.base_name(rockspec.source.url)
    local url = rockspec.source.url:gsub("^svn://", "")
-   local command = {"svn", "checkout", url, module}
+   local command = {svn_cmd, "checkout", url, module}
    if rockspec.source.tag then
       table.insert(command, 5, "-r")
       table.insert(command, 6, rockspec.source.tag)
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua
index 9cd4ca1c..d1722f4b 100644
--- a/src/luarocks/fs/unix/tools.lua
+++ b/src/luarocks/fs/unix/tools.lua
@@ -8,6 +8,8 @@ local cfg = require("luarocks.cfg")
 
 local dir_stack = {}
 
+local vars = cfg.variables
+
 --- Run the given command.
 -- The command is executed in the current directory in the dir stack.
 -- @param cmd string: No quoting/escaping is applied to the command.
@@ -26,7 +28,7 @@ end
 -- Uses the module's internal dir stack.
 -- @return string: the absolute pathname of the current directory.
 function current_dir()
-   local pipe = io.popen("pwd")
+   local pipe = io.popen(vars.PWD)
    local current = pipe:read("*l")
    pipe:close()
    for _, d in ipairs(dir_stack) do
@@ -65,7 +67,7 @@ end
 -- @return boolean: true on success, false on failure.
 function make_dir(d)
    assert(d)
-   return fs.execute("mkdir -p", d)
+   return fs.execute(vars.MKDIR.." -p", d)
 end
 
 --- Remove a directory if it is empty.
@@ -74,7 +76,7 @@ end
 -- @param dir string: pathname of directory to remove.
 function remove_dir_if_empty(d)
    assert(d)
-   fs.execute_string("rmdir "..fs.Q(d).." 1> /dev/null 2> /dev/null")
+   fs.execute_string(vars.RMDIR.." "..fs.Q(d).." 1> /dev/null 2> /dev/null")
 end
 
 --- Remove a directory if it is empty.
@@ -83,7 +85,7 @@ end
 -- @param dir string: pathname of directory to remove.
 function remove_dir_tree_if_empty(d)
    assert(d)
-   fs.execute_string("rmdir -p "..fs.Q(d).." 1> /dev/null 2> /dev/null")
+   fs.execute_string(vars.RMDIR.." -p "..fs.Q(d).." 1> /dev/null 2> /dev/null")
 end
 
 --- Copy a file.
@@ -93,7 +95,7 @@ end
 -- plus an error message.
 function copy(src, dest)
    assert(src and dest)
-   if fs.execute("cp", src, dest) then
+   if fs.execute(vars.CP, src, dest) then
       return true
    else
       return false, "Failed copying "..src.." to "..dest
@@ -107,7 +109,7 @@ end
 -- plus an error message.
 function copy_contents(src, dest)
    assert(src and dest)
-   if fs.execute_string("cp -pPR "..fs.Q(src).."/* "..fs.Q(dest).." 1> /dev/null 2>/dev/null") then
+   if fs.execute_string(vars.CP.." -pPR "..fs.Q(src).."/* "..fs.Q(dest).." 1> /dev/null 2>/dev/null") then
       return true
    else
       return false, "Failed copying "..src.." to "..dest
@@ -120,7 +122,7 @@ end
 function delete(arg)
    assert(arg)
    assert(arg:sub(1,1) == "/")
-   return fs.execute_string("rm -rf " .. fs.Q(arg) .. " 1> /dev/null 2>/dev/null")
+   return fs.execute_string(vars.RM.." -rf " .. fs.Q(arg) .. " 1> /dev/null 2>/dev/null")
 end
 
 --- List the contents of a directory. 
@@ -137,7 +139,7 @@ function list_dir(at)
       return {}
    end
    local result = {}
-   local pipe = io.popen("cd "..fs.Q(at).." && ls")
+   local pipe = io.popen("cd "..fs.Q(at).." && "..vars.LS)
    for file in pipe:lines() do
       table.insert(result, file)
    end
@@ -159,7 +161,7 @@ function find(at)
       return {}
    end
    local result = {}
-   local pipe = io.popen("cd "..fs.Q(at).." && find * 2>/dev/null") 
+   local pipe = io.popen("cd "..fs.Q(at).." && "..vars.FIND.." * 2>/dev/null") 
    for file in pipe:lines() do
       table.insert(result, file)
    end
@@ -173,7 +175,7 @@ end
 -- additional arguments.
 -- @return boolean: true on success, false on failure.
 function zip(zipfile, ...)
-   return fs.execute("zip -r", zipfile, ...)
+   return fs.execute(vars.ZIP.." -r", zipfile, ...)
 end
 
 --- Uncompress files from a .zip archive.
@@ -181,7 +183,7 @@ end
 -- @return boolean: true on success, false on failure.
 function unzip(zipfile)
    assert(zipfile)
-   return fs.execute("unzip", zipfile)
+   return fs.execute(vars.UNZIP, zipfile)
 end
 
 --- Test for existance of a file.
@@ -189,7 +191,7 @@ end
 -- @return boolean: true if file exists, false otherwise.
 function exists(file)
    assert(file)
-   return fs.execute("test -r", file)
+   return fs.execute(vars.TEST, "-r", file)
 end
 
 --- Test is file/dir is writable.
@@ -197,7 +199,7 @@ end
 -- @return boolean: true if file exists, false otherwise.
 function is_writable(file)
    assert(file)
-   return fs.execute("test -w", file)
+   return fs.execute(vars.TEST, "-w", file)
 end
 
 --- Test is pathname is a directory.
@@ -205,7 +207,7 @@ end
 -- @return boolean: true if it is a directory, false otherwise.
 function is_dir(file)
    assert(file)
-   return fs.execute("test -d", file)
+   return fs.execute(vars.TEST, "-d", file)
 end
 
 --- Test is pathname is a regular file.
@@ -213,7 +215,7 @@ end
 -- @return boolean: true if it is a regular file, false otherwise.
 function is_file(file)
    assert(file)
-   return fs.execute("test -f", file)
+   return fs.execute(vars.TEST, "-f", file)
 end
 
 --- Download a remote file.
@@ -228,7 +230,7 @@ function download(url, filename)
    assert(type(filename) == "string" or not filename)
 
    if cfg.downloader == "wget" then
-      local wget_cmd = "wget --no-check-certificate --no-cache --user-agent="..cfg.user_agent.." --quiet --continue "
+      local wget_cmd = vars.WGET.." --no-check-certificate --no-cache --user-agent="..cfg.user_agent.." --quiet --continue "
       if filename then
          return fs.execute(wget_cmd.." --output-document ", filename, url)
       else
@@ -236,13 +238,13 @@ function download(url, filename)
       end
    elseif cfg.downloader == "curl" then
       filename = filename or dir.base_name(url)
-      return fs.execute_string("curl -L --user-agent "..cfg.user_agent.." "..fs.Q(url).." 2> /dev/null 1> "..fs.Q(filename))
+      return fs.execute_string(vars.CURL.." -L --user-agent "..cfg.user_agent.." "..fs.Q(url).." 2> /dev/null 1> "..fs.Q(filename))
    end
 end
 
 function chmod(pathname, mode)
    if mode then 
-      return fs.execute("chmod "..mode, pathname)
+      return fs.execute(vars.CHMOD, mode, pathname)
    else
       return false
    end
@@ -251,7 +253,7 @@ end
 --- Apply a patch.
 -- @param patchname string: The filename of the patch.
 function apply_patch(patchname)
-   return fs.execute("patch -p1 -f -i ", patchname)
+   return fs.execute(vars.PATCH.." -p1 -f -i ", patchname)
 end
 
 --- Unpack an archive.
@@ -265,12 +267,12 @@ function unpack_archive(archive)
    local ok
    if archive:match("%.tar%.gz$") or archive:match("%.tgz$") then
       -- ok = fs.execute("tar zxvpf ", archive)
-         ok = fs.execute_string("gunzip -c "..archive.."|tar -xf -")
+         ok = fs.execute_string(vars.GUNZIP.." -c "..archive.."|"..vars.TAR.." -xf -")
    elseif archive:match("%.tar%.bz2$") then
       -- ok = fs.execute("tar jxvpf ", archive)
-         ok = fs.execute_string("bunzip2 -c "..archive.."|tar -xf -")
+         ok = fs.execute_string(vars.BUNZIP2.." -c "..archive.."|tar -xf -")
    elseif archive:match("%.zip$") then
-      ok = fs.execute("unzip ", archive)
+      ok = fs.execute(vars.UNZIP, archive)
    elseif archive:match("%.lua$") or archive:match("%.c$") then
       -- Ignore .lua and .c files; they don't need to be extracted.
       return true
@@ -285,18 +287,18 @@ function unpack_archive(archive)
 end
 
 local md5_cmd = {
-   md5sum = "md5sum ",
-   openssl = "openssl md5 ",
-   md5 = "md5 ",
+   md5sum = vars.MD5SUM,
+   openssl = vars.OPENSSL.." md5",
+   md5 = vars.MD5,
 }
-   
+
 --- Get the MD5 checksum for a file.
 -- @param file string: The file to be computed.
 -- @return string: The MD5 checksum
 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.absolute_name(file))
    local computed = pipe:read("*a")
    pipe:close()
    if not computed then return nil end
@@ -304,21 +306,8 @@ function get_md5(file)
 end
 
 function get_permissions(filename)
-   local ret
-
-   local flag
-   if cfg.is_platform("bsd") then
-      if cfg.is_platform("openbsd") then
-         flag = "-f '%Op'"
-      else
-         flag = "-f '%A'"
-      end
-   else
-      flag = "-c '%a'"
-   end
-
-   local pipe = io.popen("stat "..flag.." "..fs.Q(filename))
-   ret = pipe:read("*l")
+   local pipe = io.popen(vars.STAT.." "..vars.STATFLAG.." "..fs.Q(filename))
+   local ret = pipe:read("*l")
    pipe:close()
    return ret
 end
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua
index a3b7cdd0..5b7634cf 100644
--- a/src/luarocks/fs/win32/tools.lua
+++ b/src/luarocks/fs/win32/tools.lua
@@ -10,6 +10,8 @@ local dir = require("luarocks.dir")
 
 local dir_stack = {}
 
+local vars = cfg.variables
+
 --- Strip the last extension of a filename.
 -- Example: "foo.tar.gz" becomes "foo.tar".
 -- If filename has no dots, returns it unchanged.
@@ -43,7 +45,7 @@ end
 -- Uses the module's internal dir stack.
 -- @return string: the absolute pathname of the current directory.
 function current_dir()
-   local pipe = io.popen("pwd")
+   local pipe = io.popen(vars.PWD)
    local current = pipe:read("*l")
    pipe:close()
    for _, d in ipairs(dir_stack) do
@@ -57,22 +59,22 @@ end
 -- @return boolean: true if it is a regular file, false otherwise.
 function is_file(file)
    assert(file)
-   return fs.execute("test -f", file)
+   return fs.execute(vars.TEST.." -f", file)
 end
 
 local md5_cmd = {
-   md5sum = "md5sum ",
-   openssl = "openssl md5 ",
-   md5 = "md5 ",
+   md5sum = vars.MD5SUM,
+   openssl = vars.OPENSSL.." md5",
+   md5 = vars.MD5,
 }
-   
+
 --- Get the MD5 checksum for a file.
 -- @param file string: The file to be computed.
 -- @return string: The MD5 checksum
 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.absolute_name(file))
    local computed = pipe:read("*a")
    pipe:close()
    if not computed then return nil end
@@ -120,7 +122,7 @@ end
 -- @return boolean: true if it is a regular file, false otherwise.
 function is_dir(file)
    assert(file)
-   return fs.execute("test -d " .. fs.Q(file) .. " 2>NUL 1>NUL")
+   return fs.execute(vars.TEST.." -d " .. fs.Q(file) .. " 2>NUL 1>NUL")
 end
 
 --- Create a directory if it does not already exist.
@@ -130,7 +132,7 @@ end
 -- @return boolean: true on success, false on failure.
 function make_dir(d)
    assert(d)
-   fs.execute("mkdir "..fs.Q(d).." 1> NUL 2> NUL")
+   fs.execute(vars.MKDIR.." "..fs.Q(d).." 1> NUL 2> NUL")
    return 1
 end
 
@@ -140,7 +142,7 @@ end
 -- @param d string: pathname of directory to remove.
 function remove_dir_if_empty(d)
    assert(d)
-   fs.execute_string("rmdir "..fs.Q(d).." 1> NUL 2> NUL")
+   fs.execute_string(vars.RMDIR.." "..fs.Q(d).." 1> NUL 2> NUL")
 end
 
 --- Remove a directory if it is empty.
@@ -149,7 +151,7 @@ end
 -- @param dir string: pathname of directory to remove.
 function remove_dir_tree_if_empty(d)
    assert(d)
-   fs.execute_string("rmdir "..fs.Q(d).." 1> NUL 2> NUL")
+   fs.execute_string(vars.RMDIR.." "..fs.Q(d).." 1> NUL 2> NUL")
 end
 
 --- Copy a file.
@@ -160,7 +162,7 @@ end
 function copy(src, dest)
    assert(src and dest)
    if dest:match("[/\\]$") then dest = dest:sub(1, -2) end
-   if fs.execute("cp", src, dest) then
+   if fs.execute(vars.CP, src, dest) then
       return true
    else
       return false, "Failed copying "..src.." to "..dest
@@ -174,7 +176,7 @@ end
 -- plus an error message.
 function copy_contents(src, dest)
    assert(src and dest)
-   if fs.execute_string("cp -a "..src.."\\*.* "..fs.Q(dest).." 1> NUL 2> NUL") then
+   if fs.execute_string(vars.CP.." -a "..src.."\\*.* "..fs.Q(dest).." 1> NUL 2> NUL") then
       return true
    else
       return false, "Failed copying "..src.." to "..dest
@@ -188,8 +190,8 @@ end
 function delete(arg)
    assert(arg)
    assert(arg:match("^[\a-zA-Z]?:?[\\/]"))
-   fs.execute("chmod a+rw -R ", arg)
-   return fs.execute_string("rm -rf " .. fs.Q(arg) .. " 1> NUL 2> NUL")
+   fs.execute(vars.CHMOD.." a+rw -R ", arg)
+   return fs.execute_string(vars.RM.." -rf " .. fs.Q(arg) .. " 1> NUL 2> NUL")
 end
 
 --- List the contents of a directory.
@@ -206,7 +208,7 @@ function list_dir(at)
       return {}
    end
    local result = {}
-   local pipe = io.popen(command_at(at, "ls"))
+   local pipe = io.popen(command_at(at, vars.LS))
    for file in pipe:lines() do
       table.insert(result, file)
    end
@@ -229,7 +231,7 @@ function find(at)
       return {}
    end
    local result = {}
-   local pipe = io.popen(command_at(at, "find 2> NUL"))
+   local pipe = io.popen(command_at(at, vars.FIND.." 2> NUL"))
    for file in pipe:lines() do
       -- Windows find is a bit different
       local first_two = file:sub(1,2)
@@ -253,7 +255,7 @@ function download(url, filename)
    assert(type(filename) == "string" or not filename)
 
    if cfg.downloader == "wget" then
-      local wget_cmd = "wget --no-check-certificate --no-cache --user-agent="..cfg.user_agent.." --quiet --continue "
+      local wget_cmd = vars.WGET.." --no-check-certificate --no-cache --user-agent="..cfg.user_agent.." --quiet --continue "
       if filename then
          return fs.execute(wget_cmd.." --output-document ", filename, url)
       else
@@ -261,7 +263,7 @@ function download(url, filename)
       end
    elseif cfg.downloader == "curl" then
       filename = filename or dir.base_name(url)
-      return fs.execute_string("curl -L --user-agent "..cfg.user_agent.." "..fs.Q(url).." 2> NUL 1> "..fs.Q(filename))
+      return fs.execute_string(vars.CURL.." -L --user-agent "..cfg.user_agent.." "..fs.Q(url).." 2> NUL 1> "..fs.Q(filename))
    end
 end
 
@@ -272,7 +274,7 @@ end
 -- additional arguments.
 -- @return boolean: true on success, false on failure.
 function zip(zipfile, ...)
-   return fs.execute("7z a -tzip", zipfile, ...)
+   return fs.execute(vars.SEVENZ.." a -tzip", zipfile, ...)
 end
 
 --- Uncompress files from a .zip archive.
@@ -280,14 +282,14 @@ end
 -- @return boolean: true on success, false on failure.
 function unzip(zipfile)
    assert(zipfile)
-   return fs.execute("7z x", zipfile)
+   return fs.execute(vars.SEVENZ.." x", zipfile)
 end
 
 --- Uncompress gzip file.
 -- @param archive string: Filename of archive.
 -- @return boolean : success status
 local function gunzip(archive)
-  return fs.execute("7z x", archive)
+  return fs.execute(vars.SEVENZ.." x", archive)
 end
 
 --- Unpack an archive.
@@ -299,23 +301,24 @@ function unpack_archive(archive)
    assert(type(archive) == "string")
 
    local ok
+   local sevenzx = vars.SEVENZ.." x"
    if archive:match("%.tar%.gz$") then
       ok = gunzip(archive)
       if ok then
-         ok = fs.execute("7z x", strip_extension(archive))
+         ok = fs.execute(sevenzx, strip_extension(archive))
       end
    elseif archive:match("%.tgz$") then
       ok = gunzip(archive)
       if ok then
-         ok = fs.execute("7z x ", strip_extension(archive)..".tar")
+         ok = fs.execute(sevenzx, strip_extension(archive)..".tar")
       end
    elseif archive:match("%.tar%.bz2$") then
-      ok = fs.execute("7z x ", archive)
+      ok = fs.execute(sevenzx, archive)
       if ok then
-         ok = fs.execute("7z x ", strip_extension(archive))
+         ok = fs.execute(sevenzx, strip_extension(archive))
       end
    elseif archive:match("%.zip$") then
-      ok = fs.execute("7z x ", archive)
+      ok = fs.execute(sevenzx, archive)
    elseif archive:match("%.lua$") or archive:match("%.c$") then
       -- Ignore .lua and .c files; they don't need to be extracted.
       return true
-- 
cgit v1.2.3-55-g6feb