aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/luarocks/build/cmake.lua2
-rw-r--r--src/luarocks/fs/lua.lua27
-rw-r--r--src/luarocks/fs/unix/tools.lua10
-rw-r--r--src/luarocks/fs/win32/tools.lua24
-rw-r--r--src/luarocks/persist.lua2
5 files changed, 41 insertions, 24 deletions
diff --git a/src/luarocks/build/cmake.lua b/src/luarocks/build/cmake.lua
index 82f4ff58..f1737876 100644
--- a/src/luarocks/build/cmake.lua
+++ b/src/luarocks/build/cmake.lua
@@ -22,7 +22,7 @@ function run(rockspec)
22 22
23 util.variable_substitutions(variables, rockspec.variables) 23 util.variable_substitutions(variables, rockspec.variables)
24 24
25 if not fs.execute_string(fs.quiet(rockspec.variables.CMAKE.." --help")) then 25 if not fs.execute_quiet(rockspec.variables.CMAKE, "--help")) then
26 return nil, "'"..rockspec.variables.CMAKE.."' program not found. Is cmake installed? You may want to edit variables.CMAKE" 26 return nil, "'"..rockspec.variables.CMAKE.."' program not found. Is cmake installed? You may want to edit variables.CMAKE"
27 end 27 end
28 28
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua
index f50ecf75..32aac6d6 100644
--- a/src/luarocks/fs/lua.lua
+++ b/src/luarocks/fs/lua.lua
@@ -83,6 +83,15 @@ function make_temp_dir(name)
83 end 83 end
84end 84end
85 85
86local function quote_args(command, ...)
87 local out = { command }
88 for _, arg in ipairs({...}) do
89 assert(type(arg) == "string")
90 out[#out+1] = fs.Q(arg)
91 end
92 return table.concat(out, " ")
93end
94
86--- Run the given command, quoting its arguments. 95--- Run the given command, quoting its arguments.
87-- The command is executed in the current directory in the dir stack. 96-- The command is executed in the current directory in the dir stack.
88-- @param command string: The command to be executed. No quoting/escaping 97-- @param command string: The command to be executed. No quoting/escaping
@@ -92,12 +101,19 @@ end
92-- otherwise. 101-- otherwise.
93function execute(command, ...) 102function execute(command, ...)
94 assert(type(command) == "string") 103 assert(type(command) == "string")
104 return fs.execute_string(quote_args(command, ...))
105end
95 106
96 for _, arg in ipairs({...}) do 107--- Run the given command, quoting its arguments, silencing its output.
97 assert(type(arg) == "string") 108-- The command is executed in the current directory in the dir stack.
98 command = command .. " " .. fs.Q(arg) 109-- @param command string: The command to be executed. No quoting/escaping
99 end 110-- is applied.
100 return fs.execute_string(command) 111-- @param ... Strings containing additional arguments, which are quoted.
112-- @return boolean: true if command succeeds (status code 0), false
113-- otherwise.
114function execute_quiet(command, ...)
115 assert(type(command) == "string")
116 return fs.execute_string(fs.quiet(quote_args(command, ...)))
101end 117end
102 118
103--- Check the MD5 checksum for a file. 119--- Check the MD5 checksum for a file.
@@ -482,6 +498,7 @@ if socket_ok then
482 498
483local ltn12 = require("ltn12") 499local ltn12 = require("ltn12")
484local luasec_ok, https = pcall(require, "ssl.https") 500local luasec_ok, https = pcall(require, "ssl.https")
501
485local redirect_protocols = { 502local redirect_protocols = {
486 http = http, 503 http = http,
487 https = luasec_ok and https, 504 https = luasec_ok and https,
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua
index 9e4acf73..1b2931e9 100644
--- a/src/luarocks/fs/unix/tools.lua
+++ b/src/luarocks/fs/unix/tools.lua
@@ -88,7 +88,7 @@ end
88-- @param directory string: pathname of directory to remove. 88-- @param directory string: pathname of directory to remove.
89function remove_dir_if_empty(directory) 89function remove_dir_if_empty(directory)
90 assert(directory) 90 assert(directory)
91 fs.execute_string(fs.quiet(vars.RMDIR.." "..fs.Q(directory))) 91 fs.execute_quiet(vars.RMDIR, directory)
92end 92end
93 93
94--- Remove a directory if it is empty. 94--- Remove a directory if it is empty.
@@ -97,7 +97,7 @@ end
97-- @param directory string: pathname of directory to remove. 97-- @param directory string: pathname of directory to remove.
98function remove_dir_tree_if_empty(directory) 98function remove_dir_tree_if_empty(directory)
99 assert(directory) 99 assert(directory)
100 fs.execute_string(fs.quiet(vars.RMDIR.." -p "..fs.Q(directory))) 100 fs.execute_quiet(vars.RMDIR, "-p", directory)
101end 101end
102 102
103--- Copy a file. 103--- Copy a file.
@@ -132,7 +132,7 @@ end
132-- plus an error message. 132-- plus an error message.
133function copy_contents(src, dest) 133function copy_contents(src, dest)
134 assert(src and dest) 134 assert(src and dest)
135 if fs.execute_string(fs.quiet(vars.CP.." -pPR "..fs.Q(src).."/* "..fs.Q(dest))) then 135 if fs.execute_quiet(vars.CP.." -pPR "..fs.Q(src).."/* "..fs.Q(dest)) then
136 return true 136 return true
137 else 137 else
138 return false, "Failed copying "..src.." to "..dest 138 return false, "Failed copying "..src.." to "..dest
@@ -145,7 +145,7 @@ end
145function delete(arg) 145function delete(arg)
146 assert(arg) 146 assert(arg)
147 assert(arg:sub(1,1) == "/") 147 assert(arg:sub(1,1) == "/")
148 return fs.execute_string(fs.quiet(vars.RM.." -rf " .. fs.Q(arg))) 148 return fs.execute_quiet(vars.RM, "-rf", arg)
149end 149end
150 150
151--- List the contents of a directory. 151--- List the contents of a directory.
@@ -206,7 +206,7 @@ end
206-- @return boolean: true on success, false on failure. 206-- @return boolean: true on success, false on failure.
207function unzip(zipfile) 207function unzip(zipfile)
208 assert(zipfile) 208 assert(zipfile)
209 return fs.execute_string(fs.quiet(vars.UNZIP.." "..fs.Q(zipfile))) 209 return fs.execute_quiet(vars.UNZIP, zipfile)
210end 210end
211 211
212--- Test is file/directory exists 212--- Test is file/directory exists
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua
index f60b8f5b..b8f9bd36 100644
--- a/src/luarocks/fs/win32/tools.lua
+++ b/src/luarocks/fs/win32/tools.lua
@@ -108,7 +108,7 @@ end
108function make_dir(directory) 108function make_dir(directory)
109 assert(directory) 109 assert(directory)
110 directory = dir.normalize(directory) 110 directory = dir.normalize(directory)
111 fs.execute(fs.quiet(vars.MKDIR.." -p "..fs.Q(directory))) 111 fs.execute_quiet(vars.MKDIR.." -p ", directory)
112 if not fs.is_dir(directory) then 112 if not fs.is_dir(directory) then
113 return false, "failed making directory "..directory 113 return false, "failed making directory "..directory
114 end 114 end
@@ -121,7 +121,7 @@ end
121-- @param directory string: pathname of directory to remove. 121-- @param directory string: pathname of directory to remove.
122function remove_dir_if_empty(directory) 122function remove_dir_if_empty(directory)
123 assert(directory) 123 assert(directory)
124 fs.execute_string(fs.quiet(vars.RMDIR.." "..fs.Q(directory))) 124 fs.execute_quiet(vars.RMDIR, directory)
125end 125end
126 126
127--- Remove a directory if it is empty. 127--- Remove a directory if it is empty.
@@ -130,7 +130,7 @@ end
130-- @param directory string: pathname of directory to remove. 130-- @param directory string: pathname of directory to remove.
131function remove_dir_tree_if_empty(directory) 131function remove_dir_tree_if_empty(directory)
132 assert(directory) 132 assert(directory)
133 fs.execute_string(fs.quiet(vars.RMDIR.." "..fs.Q(directory))) 133 fs.execute_quiet(vars.RMDIR, directory)
134end 134end
135 135
136--- Copy a file. 136--- Copy a file.
@@ -155,7 +155,7 @@ end
155-- plus an error message. 155-- plus an error message.
156function copy_contents(src, dest) 156function copy_contents(src, dest)
157 assert(src and dest) 157 assert(src and dest)
158 if fs.execute_string(fs.quiet(vars.CP.." -dR "..src.."\\*.* "..fs.Q(dest))) then 158 if fs.execute_quiet(vars.CP.." -dR "..src.."\\*.* "..fs.Q(dest)) then
159 return true 159 return true
160 else 160 else
161 return false, "Failed copying "..src.." to "..dest 161 return false, "Failed copying "..src.." to "..dest
@@ -170,7 +170,7 @@ function delete(arg)
170 assert(arg) 170 assert(arg)
171 assert(arg:match("^[\a-zA-Z]?:?[\\/]")) 171 assert(arg:match("^[\a-zA-Z]?:?[\\/]"))
172 fs.execute(vars.CHMOD.." a+rw -R ", arg) 172 fs.execute(vars.CHMOD.." a+rw -R ", arg)
173 return fs.execute_string(fs.quiet(vars.RM.." -rf " .. fs.Q(arg))) 173 return fs.execute_quiet(vars.RM.." -rf ", arg)
174end 174end
175 175
176--- List the contents of a directory. 176--- List the contents of a directory.
@@ -245,7 +245,7 @@ end
245-- @return boolean: true if it is a directory, false otherwise. 245-- @return boolean: true if it is a directory, false otherwise.
246function is_dir(file) 246function is_dir(file)
247 assert(file) 247 assert(file)
248 return fs.execute(fs.quiet(vars.TEST.." -d " .. fs.Q(file))) 248 return fs.execute_quiet(vars.TEST.." -d ", file)
249end 249end
250 250
251--- Test is pathname is a regular file. 251--- Test is pathname is a regular file.
@@ -301,20 +301,20 @@ function unpack_archive(archive)
301 if archive:match("%.tar%.gz$") then 301 if archive:match("%.tar%.gz$") then
302 ok = gunzip(archive) 302 ok = gunzip(archive)
303 if ok then 303 if ok then
304 ok = fs.execute(sevenzx, strip_extension(archive)) 304 ok = fs.execute_quiet(sevenzx, strip_extension(archive))
305 end 305 end
306 elseif archive:match("%.tgz$") then 306 elseif archive:match("%.tgz$") then
307 ok = gunzip(archive) 307 ok = gunzip(archive)
308 if ok then 308 if ok then
309 ok = fs.execute(sevenzx, strip_extension(archive)..".tar") 309 ok = fs.execute_quiet(sevenzx, strip_extension(archive)..".tar")
310 end 310 end
311 elseif archive:match("%.tar%.bz2$") then 311 elseif archive:match("%.tar%.bz2$") then
312 ok = fs.execute(sevenzx, archive) 312 ok = fs.execute_quiet(sevenzx, archive)
313 if ok then 313 if ok then
314 ok = fs.execute(sevenzx, strip_extension(archive)) 314 ok = fs.execute_quiet(sevenzx, strip_extension(archive))
315 end 315 end
316 elseif archive:match("%.zip$") then 316 elseif archive:match("%.zip$") then
317 ok = fs.execute(sevenzx, archive) 317 ok = fs.execute_quiet(sevenzx, archive)
318 elseif archive:match("%.lua$") or archive:match("%.c$") then 318 elseif archive:match("%.lua$") or archive:match("%.c$") then
319 -- Ignore .lua and .c files; they don't need to be extracted. 319 -- Ignore .lua and .c files; they don't need to be extracted.
320 return true 320 return true
@@ -352,5 +352,5 @@ end
352-- @return boolean: true if file exists, false otherwise. 352-- @return boolean: true if file exists, false otherwise.
353function exists(file) 353function exists(file)
354 assert(file) 354 assert(file)
355 return fs.execute(fs.quiet("if not exist " .. fs.Q(file) .. " invalidcommandname")) 355 return fs.execute_quiet("if not exist " .. fs.Q(file) .. " invalidcommandname")
356end 356end
diff --git a/src/luarocks/persist.lua b/src/luarocks/persist.lua
index 376a242a..5b92f9cb 100644
--- a/src/luarocks/persist.lua
+++ b/src/luarocks/persist.lua
@@ -170,4 +170,4 @@ function save_from_table(filename, tbl, field_order)
170 write_table(out, tbl, field_order) 170 write_table(out, tbl, field_order)
171 out:close() 171 out:close()
172 return true 172 return true
173end 173end \ No newline at end of file