From d17e85ebdb4b1f9204505c1bed1b8dae3b80f2af Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Sun, 19 Feb 2023 23:20:44 -0500 Subject: Added in purge, and added in additional paths. --- src/lpm.lua | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/lpm.lua b/src/lpm.lua index 7af1f0f..0261065 100644 --- a/src/lpm.lua +++ b/src/lpm.lua @@ -408,10 +408,17 @@ function common.mkdirp(path) local stat = system.stat(path) if stat and stat.type == "dir" then return true end if stat and stat.type == "file" then error("path " .. path .. " exists") end + local segments = { common.split("[/\\]", path) } local target - for _, dirname in ipairs({ common.split("[/\\]", path) }) do + local extant_root = 0 + for i, dirname in ipairs(segments) do -- we need to do this, incase directories earlier in the chain exist, but we don't have permission to read. target = target and target .. PATHSEP .. dirname or dirname - if target ~= "" and not target:find("^[A-Z]:$") and not system.stat(target) then system.mkdir(target) end + if system.stat(target) then extant_root = i end + end + target = nil + for i, dirname in ipairs(segments) do + target = target and target .. PATHSEP .. dirname or dirname + if i >= extant_root and target ~= "" and not target:find("^[A-Z]:$") and not system.stat(target) then system.mkdir(target) end end end function common.copy(src, dst, hidden) @@ -1014,7 +1021,8 @@ function Repository:fetch() if not status then if path then common.rmrf(path) - if #system.ls(common.dirname(path)) == 0 then common.rmrf(common.dirname(path)) end + local dir = common.dirname(path) + if system.stat(dir) and #system.ls(dir) == 0 then common.rmrf(dir) end end error(err) end -- cgit v1.2.3