aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Melnichenko <mpeterval@gmail.com>2016-05-07 14:22:59 +0300
committerPeter Melnichenko <mpeterval@gmail.com>2016-05-22 19:50:40 +0300
commit8630313d665904e21edcc954e4ca0d043b217665 (patch)
tree132d32dec2b03e3dcfc979b959f932cac277f3c6
parent470ca122e9120caac00cae44b472965a8828afb4 (diff)
downloadluarocks-8630313d665904e21edcc954e4ca0d043b217665.tar.gz
luarocks-8630313d665904e21edcc954e4ca0d043b217665.tar.bz2
luarocks-8630313d665904e21edcc954e4ca0d043b217665.zip
Move common implementation of tools.execute_string
-rw-r--r--src/luarocks/fs/tools.lua17
-rw-r--r--src/luarocks/fs/unix/tools.lua16
-rw-r--r--src/luarocks/fs/win32/tools.lua17
3 files changed, 17 insertions, 33 deletions
diff --git a/src/luarocks/fs/tools.lua b/src/luarocks/fs/tools.lua
index 76b90383..6caa07f3 100644
--- a/src/luarocks/fs/tools.lua
+++ b/src/luarocks/fs/tools.lua
@@ -55,6 +55,23 @@ function tools.pop_dir()
55 return directory ~= nil 55 return directory ~= nil
56end 56end
57 57
58--- Run the given command.
59-- The command is executed in the current directory in the directory stack.
60-- @param cmd string: No quoting/escaping is applied to the command.
61-- @return boolean: true if command succeeds (status code 0), false
62-- otherwise.
63function tools.execute_string(cmd)
64 local current = fs.current_dir()
65 if not current then return false end
66 cmd = fs.command_at(current, cmd)
67 local code = os.execute(cmd)
68 if code == 0 or code == true then
69 return true
70 else
71 return false
72 end
73end
74
58--- Download a remote file. 75--- Download a remote file.
59-- @param url string: URL to be fetched. 76-- @param url string: URL to be fetched.
60-- @param filename string or nil: this function attempts to detect the 77-- @param filename string or nil: this function attempts to detect the
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua
index 807f8057..1bc307a4 100644
--- a/src/luarocks/fs/unix/tools.lua
+++ b/src/luarocks/fs/unix/tools.lua
@@ -17,22 +17,6 @@ function tools.command_at(directory, cmd)
17 return "cd " .. fs.Q(fs.absolute_name(directory)) .. " && " .. cmd 17 return "cd " .. fs.Q(fs.absolute_name(directory)) .. " && " .. cmd
18end 18end
19 19
20--- Run the given command.
21-- The command is executed in the current directory in the directory stack.
22-- @param cmd string: No quoting/escaping is applied to the command.
23-- @return boolean: true if command succeeds (status code 0), false
24-- otherwise.
25function tools.execute_string(cmd)
26 local current = fs.current_dir()
27 if not current then return false end
28 local code, err = os.execute(fs.command_at(current, cmd))
29 if code == 0 or code == true then
30 return true
31 else
32 return false
33 end
34end
35
36--- Create a directory if it does not already exist. 20--- Create a directory if it does not already exist.
37-- If any of the higher levels in the path name does not exist 21-- If any of the higher levels in the path name does not exist
38-- too, they are created as well. 22-- too, they are created as well.
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua
index f2d62f32..f54ec9a5 100644
--- a/src/luarocks/fs/win32/tools.lua
+++ b/src/luarocks/fs/win32/tools.lua
@@ -24,23 +24,6 @@ function tools.command_at(directory, cmd)
24 return cmd 24 return cmd
25end 25end
26 26
27--- Run the given command.
28-- The command is executed in the current directory in the directory stack.
29-- @param cmd string: No quoting/escaping is applied to the command.
30-- @return boolean: true if command succeeds (status code 0), false
31-- otherwise.
32function tools.execute_string(cmd)
33 local current = fs.current_dir()
34 if not current then return false end
35 cmd = fs.command_at(current, cmd)
36 local code = os.execute(cmd)
37 if code == 0 or code == true then
38 return true
39 else
40 return false
41 end
42end
43
44--- Create a directory if it does not already exist. 27--- Create a directory if it does not already exist.
45-- If any of the higher levels in the path name does not exist 28-- If any of the higher levels in the path name does not exist
46-- too, they are created as well. 29-- too, they are created as well.