aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2013-10-18 18:07:17 -0300
committerHisham Muhammad <hisham@gobolinux.org>2013-10-18 18:07:17 -0300
commit7559598e6a126460ca521439aa89ce352b800a03 (patch)
treeeae2ae9a9f7ac4d6647c3bb584f1900a2661ccdf
parente86821595639434245611929b18445278e321c68 (diff)
downloadluarocks-7559598e6a126460ca521439aa89ce352b800a03.tar.gz
luarocks-7559598e6a126460ca521439aa89ce352b800a03.tar.bz2
luarocks-7559598e6a126460ca521439aa89ce352b800a03.zip
Fix behavior on nonexisting files, and while we're at it make it more efficient and less prone to race conditions.
-rw-r--r--src/luarocks/fs/lua.lua16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua
index 0e81d877..707b82bd 100644
--- a/src/luarocks/fs/lua.lua
+++ b/src/luarocks/fs/lua.lua
@@ -328,11 +328,9 @@ end
328-- @return boolean or (boolean, string): true on success, 328-- @return boolean or (boolean, string): true on success,
329-- or nil and an error message on failure. 329-- or nil and an error message on failure.
330local function recursive_delete(name) 330local function recursive_delete(name)
331 local mode = lfs.attributes(name, "mode") 331 local ok = os.remove(name)
332 332 if ok then return true end
333 if mode == "file" then 333 local pok, ok, err = pcall(function()
334 return os.remove(name)
335 elseif mode == "directory" then
336 for file in lfs.dir(name) do 334 for file in lfs.dir(name) do
337 if file ~= "." and file ~= ".." then 335 if file ~= "." and file ~= ".." then
338 local ok, err = recursive_delete(dir.path(name, file)) 336 local ok, err = recursive_delete(dir.path(name, file))
@@ -340,9 +338,13 @@ local function recursive_delete(name)
340 end 338 end
341 end 339 end
342 local ok, err = lfs.rmdir(name) 340 local ok, err = lfs.rmdir(name)
343 if not ok then return nil, err end 341 return ok, (not ok) and err
342 end)
343 if pok then
344 return ok, err
345 else
346 return pok, ok
344 end 347 end
345 return true
346end 348end
347 349
348--- Delete a file or a directory and all its contents. 350--- Delete a file or a directory and all its contents.