From 8630313d665904e21edcc954e4ca0d043b217665 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Sat, 7 May 2016 14:22:59 +0300 Subject: Move common implementation of tools.execute_string --- src/luarocks/fs/tools.lua | 17 +++++++++++++++++ src/luarocks/fs/unix/tools.lua | 16 ---------------- src/luarocks/fs/win32/tools.lua | 17 ----------------- 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() 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 = fs.current_dir() + if not current then return false end + cmd = fs.command_at(current, cmd) + local code = os.execute(cmd) + if code == 0 or code == true then + return true + else + return false + end +end + --- Download a remote file. -- @param url string: URL to be fetched. -- @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) return "cd " .. fs.Q(fs.absolute_name(directory)) .. " && " .. cmd 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 = fs.current_dir() - if not current then return false end - local code, err = os.execute(fs.command_at(current, cmd)) - if code == 0 or code == true then - return true - else - return false - end -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. 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) return cmd 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 = fs.current_dir() - if not current then return false end - cmd = fs.command_at(current, cmd) - local code = os.execute(cmd) - if code == 0 or code == true then - return true - else - return false - end -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. -- cgit v1.2.3-55-g6feb