From ed118e551d0a88c3679ab06543df020443e7f8d6 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sun, 27 Oct 2013 14:07:07 -0200 Subject: Should fix build on Windows. See #167. Also, speeds up operations on Windows considerably. --- src/luarocks/admin_remove.lua | 3 ++- src/luarocks/fs/lua.lua | 8 ++++---- src/luarocks/fs/unix/tools.lua | 4 ++-- src/luarocks/fs/win32/tools.lua | 20 ++++++++++++-------- src/luarocks/repos.lua | 9 +++++---- 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 local basename = dir.base_name(rockfile) local file = dir.path(local_cache, basename) util.printout("Removing file "..file.."...") - if fs.delete(file) then + fs.delete(file) + if fs.exists(file) then nr_files = nr_files + 1 else 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 --- Delete a file or a directory and all its contents. -- @param name string: Pathname of source --- @return boolean: true on success, false on failure. +-- @return nil function delete(name) name = dir.normalize(name) - return recursive_delete(name) or false + recursive_delete(name) end --- List the contents of a directory. @@ -723,8 +723,8 @@ function move(src, dest) if not ok then return false, err end - ok = fs.delete(src) - if not ok then + fs.delete(src) + if fs.exists(src) then return false, "Failed move: could not delete "..src.." after copy." end 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 --- Delete a file or a directory and all its contents. -- For safety, this only accepts absolute paths. -- @param arg string: Pathname of source --- @return boolean: true on success, false on failure. +-- @return nil function delete(arg) assert(arg) assert(arg:sub(1,1) == "/") - return fs.execute_quiet(vars.RM, "-rf", arg) + fs.execute_quiet(vars.RM, "-rf", arg) end --- 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 -- Uses the module's internal directory stack. -- @return string: the absolute pathname of the current directory. function current_dir() - local pipe = io.popen(vars.PWD) - local current = pipe:read("*l") - pipe:close() + local current = cfg.cache_pwd + if not current then + local pipe = io.popen(vars.PWD) + current = pipe:read("*l") + pipe:close() + cfg.cache_pwd = current + end for _, directory in ipairs(dir_stack) do current = fs.absolute_name(directory, current) end @@ -141,7 +145,8 @@ end function copy(src, dest) assert(src and dest) if dest:match("[/\\]$") then dest = dest:sub(1, -2) end - if fs.execute(vars.CP, src, dest) then + local ok = fs.execute(vars.CP, src, dest) + if ok then return true else return false, "Failed copying "..src.." to "..dest @@ -165,12 +170,11 @@ end --- Delete a file or a directory and all its contents. -- For safety, this only accepts absolute paths. -- @param arg string: Pathname of source --- @return boolean: true on success, false on failure. +-- @return nil function delete(arg) assert(arg) assert(arg:match("^[\a-zA-Z]?:?[\\/]")) - fs.execute(vars.CHMOD.." a+rw -R ", arg) - return fs.execute_quiet(vars.RM.." -rf ", arg) + fs.execute_quiet("if exist "..fs.Q(arg.."\\").." ( RMDIR /S /Q "..fs.Q(arg).." ) else ( DEL /Q /F "..fs.Q(arg).." )") end --- List the contents of a directory. @@ -245,7 +249,7 @@ end -- @return boolean: true if it is a directory, false otherwise. function is_dir(file) assert(file) - return fs.execute_quiet(vars.TEST.." -d ", file) + return fs.execute_quiet("if not exist " .. fs.Q(file.."\\").." invalidcommandname") end --- 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) local filenames = { filename } if suffix and suffix ~= "" then filenames = { filename..suffix, filename } end for _, name in ipairs(filenames) do - local ok, err = fs.delete(name) - if ok then + if fs.exists(name) then + fs.delete(name) + if fs.exists(name) then + return nil, "Failed deleting "..name, "fail" + end return true, name - elseif fs.exists(name) then - return nil, "Failed deleting "..name, "fail" end end return false, "File not found", "not found" -- cgit v1.2.3-55-g6feb