From 2bb3f37d5cb74358e2e962e79d7f4be26937eab7 Mon Sep 17 00:00:00 2001 From: hisham Date: Thu, 2 Apr 2009 03:31:20 +0000 Subject: Fix use of fs APIS. Report by Michal Kolodziejczyk. git-svn-id: http://luarocks.org/svn/luarocks/trunk@5 9ca3f7c1-7366-0410-b1a3-b5c78f85698c --- src/luarocks/fs/lua.lua | 60 ++++++++++++++++++++++++------------------------ src/luarocks/fs/unix.lua | 5 +++- 2 files changed, 34 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 00efd4f4..2bc13dae 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua @@ -64,36 +64,6 @@ function Q(arg) return "'" .. arg:gsub("\\", "\\\\"):gsub("'", "'\\''") .. "'" end ---- 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. --- @return boolean: true if command succeeds (status code 0), false --- otherwise. -function execute_string(cmd) - if os.execute(cmd) == 0 then - return true - else - return false - end -end - ---- Run the given command, quoting its arguments. --- The command is executed in the current directory in the dir stack. --- @param command string: The command to be executed. No quoting/escaping --- is applied. --- @param ... Strings containing additional arguments, which are quoted. --- @return boolean: true if command succeeds (status code 0), false --- otherwise. -function execute(command, ...) - assert(type(command) == "string") - - for _, arg in ipairs({...}) do - assert(type(arg) == "string") - command = command .. " " .. fs_Q(arg) - end - return fs_execute_string(command) -end - --- Test is file/dir is writable. -- Warning: testing if a file/dir is writable does not guarantee -- that it will remain writable and therefore it is no replacement @@ -175,6 +145,36 @@ end if lfs_ok then +--- 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. +-- @return boolean: true if command succeeds (status code 0), false +-- otherwise. +function execute_string(cmd) + if os.execute(cmd) == 0 then + return true + else + return false + end +end + +--- Run the given command, quoting its arguments. +-- The command is executed in the current directory in the dir stack. +-- @param command string: The command to be executed. No quoting/escaping +-- is applied. +-- @param ... Strings containing additional arguments, which are quoted. +-- @return boolean: true if command succeeds (status code 0), false +-- otherwise. +function execute(command, ...) + assert(type(command) == "string") + + for _, arg in ipairs({...}) do + assert(type(arg) == "string") + command = command .. " " .. fs_Q(arg) + end + return fs_execute_string(command) +end + --- Obtain current directory. -- Uses the module's internal dir stack. -- @return string: the absolute pathname of the current directory. diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index 11378854..dae6259d 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua @@ -457,7 +457,10 @@ end -- @param filename string: the file name with full path. -- @return boolean: returns true if file is an actual binary -- (or if it couldn't check) or false if it is a Lua wrapper. -local function is_actual_binary(filename) +function is_actual_binary(filename) + if filename:match("%.lua$") then + return false + end local file = io.open(filename) if file then local found = false -- cgit v1.2.3-55-g6feb