Skip to content

Commit

Permalink
fix windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed Jan 6, 2021
1 parent 435322c commit 7eaa4c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions lua/pl/dir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,22 @@ function dir.rmtree(fullpath)
for root,dirs,files in dir.walk(fullpath,true) do
if path.islink(root) then
-- sub dir is a link, remove link, do not follow
local res, err = remove(root)
if not res then return nil,err end
if is_windows then
-- Windows requires using "rmdir". Deleting the link like a file
-- will instead delete all files from the target directory!!
local res, err = rmdir(root)
if not res then return nil,err .. ": " .. root end
else
local res, err = remove(root)
if not res then return nil,err .. ": " .. root end
end
else
for i,f in ipairs(files) do
local res, err = remove(path.join(root,f))
if not res then return nil,err end
if not res then return nil,err .. ": " .. path.join(root,f) end
end
local res, err = rmdir(root)
if not res then return nil,err end
if not res then return nil,err .. ": " .. root end
end
end
return true
Expand Down
2 changes: 1 addition & 1 deletion tests/test-dir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ do
assert(file.write(linkFile, "hello world"))

local linkSource = path.normpath(dirName .. "/link1")
assert(lfs.link (linkTarget, linkSource ,true))
assert(lfs.link(linkTarget, linkSource, true))

-- test: rmtree will not follow symlinks
local ok, err = dir.rmtree(linkSource)
Expand Down

0 comments on commit 7eaa4c3

Please sign in to comment.