aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2013-10-27 14:07:07 -0200
committerHisham Muhammad <hisham@gobolinux.org>2013-10-27 14:07:07 -0200
commited118e551d0a88c3679ab06543df020443e7f8d6 (patch)
treef9787c00e355a10d3dbf415689323ea7d8258af9
parentabac98ae19ec838e4a301a65c76bdc236047d641 (diff)
downloadluarocks-ed118e551d0a88c3679ab06543df020443e7f8d6.tar.gz
luarocks-ed118e551d0a88c3679ab06543df020443e7f8d6.tar.bz2
luarocks-ed118e551d0a88c3679ab06543df020443e7f8d6.zip
Should fix build on Windows. See #167.
Also, speeds up operations on Windows considerably.
-rw-r--r--src/luarocks/admin_remove.lua3
-rw-r--r--src/luarocks/fs/lua.lua8
-rw-r--r--src/luarocks/fs/unix/tools.lua4
-rw-r--r--src/luarocks/fs/win32/tools.lua20
-rw-r--r--src/luarocks/repos.lua9
5 files changed, 25 insertions, 19 deletions
diff --git a/src/luarocks/admin_remove.lua b/src/luarocks/admin_remove.lua
index d429ce59..45949e3f 100644
--- a/src/luarocks/admin_remove.lua
+++ b/src/luarocks/admin_remove.lua
@@ -49,7 +49,8 @@ local function remove_files_from_server(refresh, rockfiles, server, upload_serve
49 local basename = dir.base_name(rockfile) 49 local basename = dir.base_name(rockfile)
50 local file = dir.path(local_cache, basename) 50 local file = dir.path(local_cache, basename)
51 util.printout("Removing file "..file.."...") 51 util.printout("Removing file "..file.."...")
52 if fs.delete(file) then 52 fs.delete(file)
53 if fs.exists(file) then
53 nr_files = nr_files + 1 54 nr_files = nr_files + 1
54 else 55 else
55 util.printerr("Failed removing "..file) 56 util.printerr("Failed removing "..file)
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua
index e637f6be..d477d88f 100644
--- a/src/luarocks/fs/lua.lua
+++ b/src/luarocks/fs/lua.lua
@@ -349,10 +349,10 @@ end
349 349
350--- Delete a file or a directory and all its contents. 350--- Delete a file or a directory and all its contents.
351-- @param name string: Pathname of source 351-- @param name string: Pathname of source
352-- @return boolean: true on success, false on failure. 352-- @return nil
353function delete(name) 353function delete(name)
354 name = dir.normalize(name) 354 name = dir.normalize(name)
355 return recursive_delete(name) or false 355 recursive_delete(name)
356end 356end
357 357
358--- List the contents of a directory. 358--- List the contents of a directory.
@@ -723,8 +723,8 @@ function move(src, dest)
723 if not ok then 723 if not ok then
724 return false, err 724 return false, err
725 end 725 end
726 ok = fs.delete(src) 726 fs.delete(src)
727 if not ok then 727 if fs.exists(src) then
728 return false, "Failed move: could not delete "..src.." after copy." 728 return false, "Failed move: could not delete "..src.." after copy."
729 end 729 end
730 return true 730 return true
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua
index 2dfca715..e3468ab4 100644
--- a/src/luarocks/fs/unix/tools.lua
+++ b/src/luarocks/fs/unix/tools.lua
@@ -141,11 +141,11 @@ end
141--- Delete a file or a directory and all its contents. 141--- Delete a file or a directory and all its contents.
142-- For safety, this only accepts absolute paths. 142-- For safety, this only accepts absolute paths.
143-- @param arg string: Pathname of source 143-- @param arg string: Pathname of source
144-- @return boolean: true on success, false on failure. 144-- @return nil
145function delete(arg) 145function delete(arg)
146 assert(arg) 146 assert(arg)
147 assert(arg:sub(1,1) == "/") 147 assert(arg:sub(1,1) == "/")
148 return fs.execute_quiet(vars.RM, "-rf", arg) 148 fs.execute_quiet(vars.RM, "-rf", arg)
149end 149end
150 150
151--- List the contents of a directory. 151--- List the contents of a directory.
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua
index 6109ac8f..0568dc51 100644
--- a/src/luarocks/fs/win32/tools.lua
+++ b/src/luarocks/fs/win32/tools.lua
@@ -40,9 +40,13 @@ end
40-- Uses the module's internal directory stack. 40-- Uses the module's internal directory stack.
41-- @return string: the absolute pathname of the current directory. 41-- @return string: the absolute pathname of the current directory.
42function current_dir() 42function current_dir()
43 local pipe = io.popen(vars.PWD) 43 local current = cfg.cache_pwd
44 local current = pipe:read("*l") 44 if not current then
45 pipe:close() 45 local pipe = io.popen(vars.PWD)
46 current = pipe:read("*l")
47 pipe:close()
48 cfg.cache_pwd = current
49 end
46 for _, directory in ipairs(dir_stack) do 50 for _, directory in ipairs(dir_stack) do
47 current = fs.absolute_name(directory, current) 51 current = fs.absolute_name(directory, current)
48 end 52 end
@@ -141,7 +145,8 @@ end
141function copy(src, dest) 145function copy(src, dest)
142 assert(src and dest) 146 assert(src and dest)
143 if dest:match("[/\\]$") then dest = dest:sub(1, -2) end 147 if dest:match("[/\\]$") then dest = dest:sub(1, -2) end
144 if fs.execute(vars.CP, src, dest) then 148 local ok = fs.execute(vars.CP, src, dest)
149 if ok then
145 return true 150 return true
146 else 151 else
147 return false, "Failed copying "..src.." to "..dest 152 return false, "Failed copying "..src.." to "..dest
@@ -165,12 +170,11 @@ end
165--- Delete a file or a directory and all its contents. 170--- Delete a file or a directory and all its contents.
166-- For safety, this only accepts absolute paths. 171-- For safety, this only accepts absolute paths.
167-- @param arg string: Pathname of source 172-- @param arg string: Pathname of source
168-- @return boolean: true on success, false on failure. 173-- @return nil
169function delete(arg) 174function delete(arg)
170 assert(arg) 175 assert(arg)
171 assert(arg:match("^[\a-zA-Z]?:?[\\/]")) 176 assert(arg:match("^[\a-zA-Z]?:?[\\/]"))
172 fs.execute(vars.CHMOD.." a+rw -R ", arg) 177 fs.execute_quiet("if exist "..fs.Q(arg.."\\").." ( RMDIR /S /Q "..fs.Q(arg).." ) else ( DEL /Q /F "..fs.Q(arg).." )")
173 return fs.execute_quiet(vars.RM.." -rf ", arg)
174end 178end
175 179
176--- List the contents of a directory. 180--- List the contents of a directory.
@@ -245,7 +249,7 @@ end
245-- @return boolean: true if it is a directory, false otherwise. 249-- @return boolean: true if it is a directory, false otherwise.
246function is_dir(file) 250function is_dir(file)
247 assert(file) 251 assert(file)
248 return fs.execute_quiet(vars.TEST.." -d ", file) 252 return fs.execute_quiet("if not exist " .. fs.Q(file.."\\").." invalidcommandname")
249end 253end
250 254
251--- Test is pathname is a regular file. 255--- Test is pathname is a regular file.
diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.lua
index 86e82ec9..4a9c2f7d 100644
--- a/src/luarocks/repos.lua
+++ b/src/luarocks/repos.lua
@@ -256,11 +256,12 @@ local function delete_suffixed(filename, suffix)
256 local filenames = { filename } 256 local filenames = { filename }
257 if suffix and suffix ~= "" then filenames = { filename..suffix, filename } end 257 if suffix and suffix ~= "" then filenames = { filename..suffix, filename } end
258 for _, name in ipairs(filenames) do 258 for _, name in ipairs(filenames) do
259 local ok, err = fs.delete(name) 259 if fs.exists(name) then
260 if ok then 260 fs.delete(name)
261 if fs.exists(name) then
262 return nil, "Failed deleting "..name, "fail"
263 end
261 return true, name 264 return true, name
262 elseif fs.exists(name) then
263 return nil, "Failed deleting "..name, "fail"
264 end 265 end
265 end 266 end
266 return false, "File not found", "not found" 267 return false, "File not found", "not found"