From 7eaa4c30c7bedb4671c8c808876933c6da8dcb8b Mon Sep 17 00:00:00 2001 From: Thijs Date: Wed, 6 Jan 2021 17:23:02 +0100 Subject: [PATCH] fix windows --- lua/pl/dir.lua | 15 +++++++++++---- tests/test-dir.lua | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lua/pl/dir.lua b/lua/pl/dir.lua index 98e7df9b..56d084c0 100644 --- a/lua/pl/dir.lua +++ b/lua/pl/dir.lua @@ -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 diff --git a/tests/test-dir.lua b/tests/test-dir.lua index 44500d50..b293abc4 100644 --- a/tests/test-dir.lua +++ b/tests/test-dir.lua @@ -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)