aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--install.bat13
-rw-r--r--src/luarocks/core/cfg.lua3
-rw-r--r--src/luarocks/fs/lua.lua9
-rw-r--r--src/luarocks/fs/unix.lua40
-rw-r--r--src/luarocks/fs/unix/tools.lua24
-rw-r--r--src/luarocks/fs/win32.lua35
-rw-r--r--src/luarocks/fs/win32/tools.lua24
-rw-r--r--win32/COPYING2
-rw-r--r--win32/tools/test.exebin62976 -> 0 bytes
9 files changed, 97 insertions, 53 deletions
diff --git a/install.bat b/install.bat
index a98b32fd..43b18e1d 100644
--- a/install.bat
+++ b/install.bat
@@ -67,8 +67,17 @@ local function exec(cmd)
67end 67end
68 68
69local function exists(filename) 69local function exists(filename)
70 local cmd = [[.\win32\tools\test -e "]]..filename..[["]] 70 local fd, _, code = io.open(filename, "r")
71 return exec(cmd) 71 if code == 13 then
72 -- code 13 means "Permission denied" on both Unix and Windows
73 -- io.open on folders always fails with code 13 on Windows
74 return true
75 end
76 if fd then
77 fd:close()
78 return true
79 end
80 return false
72end 81end
73 82
74local function mkdir (dir) 83local function mkdir (dir)
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua
index 670f04b2..5b9dec2f 100644
--- a/src/luarocks/core/cfg.lua
+++ b/src/luarocks/core/cfg.lua
@@ -242,7 +242,6 @@ local function make_defaults(lua_version, target_cpu, platforms, home)
242 LS = "ls", 242 LS = "ls",
243 RM = "rm", 243 RM = "rm",
244 FIND = "find", 244 FIND = "find",
245 TEST = "test",
246 CHMOD = "chmod", 245 CHMOD = "chmod",
247 ICACLS = "icacls", 246 ICACLS = "icacls",
248 MKTEMP = "mktemp", 247 MKTEMP = "mktemp",
@@ -718,7 +717,7 @@ function cfg.init(detected, warning)
718 local defaults = make_defaults(lua_version, processor, platforms, cfg.home) 717 local defaults = make_defaults(lua_version, processor, platforms, cfg.home)
719 718
720 if platforms.windows and hardcoded.WIN_TOOLS then 719 if platforms.windows and hardcoded.WIN_TOOLS then
721 local tools = { "SEVENZ", "CP", "FIND", "LS", "MD5SUM", "PWD", "RMDIR", "TEST", "WGET", "MKDIR" } 720 local tools = { "SEVENZ", "CP", "FIND", "LS", "MD5SUM", "PWD", "RMDIR", "WGET", "MKDIR" }
722 for _, tool in ipairs(tools) do 721 for _, tool in ipairs(tools) do
723 defaults.variables[tool] = '"' .. hardcoded.WIN_TOOLS .. "/" .. defaults.variables[tool] .. '.exe"' 722 defaults.variables[tool] = '"' .. hardcoded.WIN_TOOLS .. "/" .. defaults.variables[tool] .. '.exe"'
724 end 723 end
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua
index 0976dc8d..6625ddda 100644
--- a/src/luarocks/fs/lua.lua
+++ b/src/luarocks/fs/lua.lua
@@ -590,6 +590,15 @@ function fs_lua.set_time(file, time)
590 return lfs.touch(file, time) 590 return lfs.touch(file, time)
591end 591end
592 592
593else -- if not lfs_ok
594
595function fs_lua.exists(file)
596 assert(file)
597 file = dir.normalize(fs.absolute_name(file))
598 -- check if file exists by attempting to open it
599 return util.exists(file)
600end
601
593end 602end
594 603
595--------------------------------------------------------------------- 604---------------------------------------------------------------------
diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua
index 50bfba9c..849259e8 100644
--- a/src/luarocks/fs/unix.lua
+++ b/src/luarocks/fs/unix.lua
@@ -205,4 +205,44 @@ function unix._unix_moderate_permissions(perms)
205 return moderated_perms 205 return moderated_perms
206end 206end
207 207
208function unix.is_dir(file)
209 file = fs.absolute_name(file)
210 file = dir.normalize(file) .. "/"
211 local fd, _, code = io.open(file, "r")
212 if code == 2 then -- "No such file or directory"
213 return false
214 end
215 if code == 20 then -- "Not a directory", regardless of permissions
216 return false
217 end
218 if code == 13 then -- "Permission denied", but is a directory
219 return true
220 end
221 if fd then
222 fd:close()
223 return true
224 end
225 return false
226end
227
228function unix.is_file(file)
229 file = fs.absolute_name(file)
230 if fs.is_dir(file) then
231 return false
232 end
233 file = dir.normalize(file)
234 local fd, _, code = io.open(file, "r")
235 if code == 2 then -- "No such file or directory"
236 return false
237 end
238 if code == 13 then -- "Permission denied", but it exists
239 return true
240 end
241 if fd then
242 fd:close()
243 return true
244 end
245 return false
246end
247
208return unix 248return unix
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua
index c5d83018..9a2f99a7 100644
--- a/src/luarocks/fs/unix/tools.lua
+++ b/src/luarocks/fs/unix/tools.lua
@@ -183,30 +183,6 @@ function tools.bunzip2(infile, outfile)
183 return uncompress("bz2", "bunzip2", infile, outfile) 183 return uncompress("bz2", "bunzip2", infile, outfile)
184end 184end
185 185
186--- Test is file/directory exists
187-- @param file string: filename to test
188-- @return boolean: true if file exists, false otherwise.
189function tools.exists(file)
190 assert(file)
191 return fs.execute(vars.TEST, "-e", file)
192end
193
194--- Test is pathname is a directory.
195-- @param file string: pathname to test
196-- @return boolean: true if it is a directory, false otherwise.
197function tools.is_dir(file)
198 assert(file)
199 return fs.execute(vars.TEST, "-d", file)
200end
201
202--- Test is pathname is a regular file.
203-- @param file string: pathname to test
204-- @return boolean: true if it is a regular file, false otherwise.
205function tools.is_file(file)
206 assert(file)
207 return fs.execute(vars.TEST, "-f", file)
208end
209
210do 186do
211 local function rwx_to_octal(rwx) 187 local function rwx_to_octal(rwx)
212 return (rwx:match "r" and 4 or 0) 188 return (rwx:match "r" and 4 or 0)
diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua
index 87232b77..498eceb7 100644
--- a/src/luarocks/fs/win32.lua
+++ b/src/luarocks/fs/win32.lua
@@ -234,6 +234,41 @@ function win32.replace_file(old_file, new_file)
234 return os.rename(new_file, old_file) 234 return os.rename(new_file, old_file)
235end 235end
236 236
237function win32.is_dir(file)
238 file = fs.absolute_name(file)
239 file = dir.normalize(file)
240 local fd, _, code = io.open(file, "r")
241 if code == 13 then -- directories return "Permission denied"
242 fd, _, code = io.open(file .. "\\", "r")
243 if code == 2 then -- directories return 2, files return 22
244 return true
245 end
246 end
247 if fd then
248 fd:close()
249 end
250 return false
251end
252
253function win32.is_file(file)
254 file = fs.absolute_name(file)
255 file = dir.normalize(file)
256 local fd, _, code = io.open(file, "r")
257 if code == 13 then -- if "Permission denied"
258 fd, _, code = io.open(file .. "\\", "r")
259 if code == 2 then -- directories return 2, files return 22
260 return false
261 elseif code == 22 then
262 return true
263 end
264 end
265 if fd then
266 fd:close()
267 return true
268 end
269 return false
270end
271
237--- Test is file/dir is writable. 272--- Test is file/dir is writable.
238-- Warning: testing if a file/dir is writable does not guarantee 273-- Warning: testing if a file/dir is writable does not guarantee
239-- that it will remain writable and therefore it is no replacement 274-- that it will remain writable and therefore it is no replacement
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua
index 77e962eb..f9468517 100644
--- a/src/luarocks/fs/win32/tools.lua
+++ b/src/luarocks/fs/win32/tools.lua
@@ -201,22 +201,6 @@ function tools.bunzip2(infile, outfile)
201 return sevenz("bz2", infile, outfile) 201 return sevenz("bz2", infile, outfile)
202end 202end
203 203
204--- Test is pathname is a directory.
205-- @param file string: pathname to test
206-- @return boolean: true if it is a directory, false otherwise.
207function tools.is_dir(file)
208 assert(file)
209 return fs.execute_quiet("if not exist " .. fs.Q(file.."\\").." invalidcommandname")
210end
211
212--- Test is pathname is a regular file.
213-- @param file string: pathname to test
214-- @return boolean: true if it is a regular file, false otherwise.
215function tools.is_file(file)
216 assert(file)
217 return fs.execute(vars.TEST.." -f", file)
218end
219
220--- Helper function for fs.set_permissions 204--- Helper function for fs.set_permissions
221-- @return table: an array of all system users 205-- @return table: an array of all system users
222local function get_system_users() 206local function get_system_users()
@@ -292,14 +276,6 @@ function tools.set_permissions(filename, mode, scope)
292 return true 276 return true
293end 277end
294 278
295--- Test for existence of a file.
296-- @param file string: filename to test
297-- @return boolean: true if file exists, false otherwise.
298function tools.exists(file)
299 assert(file)
300 return fs.execute_quiet("if not exist " .. fs.Q(file) .. " invalidcommandname")
301end
302
303function tools.browser(url) 279function tools.browser(url)
304 return fs.execute(cfg.web_browser..' "Starting docs..." '..fs.Q(url)) 280 return fs.execute(cfg.web_browser..' "Starting docs..." '..fs.Q(url))
305end 281end
diff --git a/win32/COPYING b/win32/COPYING
index 3413b8c2..d28b2efd 100644
--- a/win32/COPYING
+++ b/win32/COPYING
@@ -5,7 +5,7 @@ following licenses:
5* For 7z.exe and 7z.dll, please see COPYING_7z for details. 5* For 7z.exe and 7z.dll, please see COPYING_7z for details.
6 6
7* find.exe, mv.exe, wget.exe, ls.exe, pwd.exe, rmdir.exe, md5sum.exe, 7* find.exe, mv.exe, wget.exe, ls.exe, pwd.exe, rmdir.exe, md5sum.exe,
8 test.exe, cp.exe, mkdir.exe, and uname.exe are part of UnxUtils, check 8 cp.exe, mkdir.exe, and uname.exe are part of UnxUtils, check
9 http://unxutils.sourceforge.net/ for license information. 9 http://unxutils.sourceforge.net/ for license information.
10 10
11* Files under win32/lua5.1, except for Microsoft.VC80.CRT.manifest and msv*.*, 11* Files under win32/lua5.1, except for Microsoft.VC80.CRT.manifest and msv*.*,
diff --git a/win32/tools/test.exe b/win32/tools/test.exe
deleted file mode 100644
index 94c95f9e..00000000
--- a/win32/tools/test.exe
+++ /dev/null
Binary files differ