aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c>2009-04-02 03:31:20 +0000
committerhisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c>2009-04-02 03:31:20 +0000
commit2bb3f37d5cb74358e2e962e79d7f4be26937eab7 (patch)
treeeca92d91ae7972e30bed42d29a13966f527af4b8 /src
parent831a3c8a20780cb56a3e6544c62ba7eedf751ed2 (diff)
downloadluarocks-2bb3f37d5cb74358e2e962e79d7f4be26937eab7.tar.gz
luarocks-2bb3f37d5cb74358e2e962e79d7f4be26937eab7.tar.bz2
luarocks-2bb3f37d5cb74358e2e962e79d7f4be26937eab7.zip
Fix use of fs APIS. Report by Michal Kolodziejczyk.
git-svn-id: http://luarocks.org/svn/luarocks/trunk@5 9ca3f7c1-7366-0410-b1a3-b5c78f85698c
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/fs/lua.lua60
-rw-r--r--src/luarocks/fs/unix.lua5
2 files changed, 34 insertions, 31 deletions
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)
64 return "'" .. arg:gsub("\\", "\\\\"):gsub("'", "'\\''") .. "'" 64 return "'" .. arg:gsub("\\", "\\\\"):gsub("'", "'\\''") .. "'"
65end 65end
66 66
67--- Run the given command.
68-- The command is executed in the current directory in the dir stack.
69-- @param cmd string: No quoting/escaping is applied to the command.
70-- @return boolean: true if command succeeds (status code 0), false
71-- otherwise.
72function execute_string(cmd)
73 if os.execute(cmd) == 0 then
74 return true
75 else
76 return false
77 end
78end
79
80--- Run the given command, quoting its arguments.
81-- The command is executed in the current directory in the dir stack.
82-- @param command string: The command to be executed. No quoting/escaping
83-- is applied.
84-- @param ... Strings containing additional arguments, which are quoted.
85-- @return boolean: true if command succeeds (status code 0), false
86-- otherwise.
87function execute(command, ...)
88 assert(type(command) == "string")
89
90 for _, arg in ipairs({...}) do
91 assert(type(arg) == "string")
92 command = command .. " " .. fs_Q(arg)
93 end
94 return fs_execute_string(command)
95end
96
97--- Test is file/dir is writable. 67--- Test is file/dir is writable.
98-- Warning: testing if a file/dir is writable does not guarantee 68-- Warning: testing if a file/dir is writable does not guarantee
99-- that it will remain writable and therefore it is no replacement 69-- that it will remain writable and therefore it is no replacement
@@ -175,6 +145,36 @@ end
175 145
176if lfs_ok then 146if lfs_ok then
177 147
148--- Run the given command.
149-- The command is executed in the current directory in the dir stack.
150-- @param cmd string: No quoting/escaping is applied to the command.
151-- @return boolean: true if command succeeds (status code 0), false
152-- otherwise.
153function execute_string(cmd)
154 if os.execute(cmd) == 0 then
155 return true
156 else
157 return false
158 end
159end
160
161--- Run the given command, quoting its arguments.
162-- The command is executed in the current directory in the dir stack.
163-- @param command string: The command to be executed. No quoting/escaping
164-- is applied.
165-- @param ... Strings containing additional arguments, which are quoted.
166-- @return boolean: true if command succeeds (status code 0), false
167-- otherwise.
168function execute(command, ...)
169 assert(type(command) == "string")
170
171 for _, arg in ipairs({...}) do
172 assert(type(arg) == "string")
173 command = command .. " " .. fs_Q(arg)
174 end
175 return fs_execute_string(command)
176end
177
178--- Obtain current directory. 178--- Obtain current directory.
179-- Uses the module's internal dir stack. 179-- Uses the module's internal dir stack.
180-- @return string: the absolute pathname of the current directory. 180-- @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
457-- @param filename string: the file name with full path. 457-- @param filename string: the file name with full path.
458-- @return boolean: returns true if file is an actual binary 458-- @return boolean: returns true if file is an actual binary
459-- (or if it couldn't check) or false if it is a Lua wrapper. 459-- (or if it couldn't check) or false if it is a Lua wrapper.
460local function is_actual_binary(filename) 460function is_actual_binary(filename)
461 if filename:match("%.lua$") then
462 return false
463 end
461 local file = io.open(filename) 464 local file = io.open(filename)
462 if file then 465 if file then
463 local found = false 466 local found = false