diff options
-rw-r--r-- | plugins/plugin_manager/init.lua | 8 | ||||
-rw-r--r-- | src/lpm.lua | 14 |
2 files changed, 19 insertions, 3 deletions
diff --git a/plugins/plugin_manager/init.lua b/plugins/plugin_manager/init.lua index 9dee036..3e69884 100644 --- a/plugins/plugin_manager/init.lua +++ b/plugins/plugin_manager/init.lua @@ -41,6 +41,7 @@ if not config.plugins.plugin_manager.lpm_binary_path then local path, s = os.getenv("PATH"), 1 while true do local _, e = path:find(":", s) + table.insert(paths, path:sub(s, e and (e-1) or #path) .. PATHSEP .. config.plugins.plugin_manager.lpm_binary_name) table.insert(paths, path:sub(s, e and (e-1) or #path) .. PATHSEP .. "lpm" .. binary_extension) if not e then break end s = e + 1 @@ -176,6 +177,12 @@ function PluginManager:upgrade(progress) end + +function PluginManager:purge(progress) + return run({ "purge" }, progress) +end + + function PluginManager:get_addons() local prom = Promise.new() if self.addons then @@ -312,6 +319,7 @@ command.add(nil, { end, ["plugin-manager:refresh"] = function() PluginManager:refresh(PluginManager.view.progress_callback):done(function() core.log("Successfully refreshed plugin listing.") end) end, ["plugin-manager:upgrade"] = function() PluginManager:upgrade(PluginManager.view.progress_callback):done(function() core.log("Successfully upgraded installed plugins.") end) end, + ["plugin-manager:purge"] = function() PluginManager:purge(PluginManager.view.progress_callback):done(function() core.log("Successfully purged lpm directory.") end) end, ["plugin-manager:show"] = function() local node = core.root_view:get_active_node_default() node:add_view(PluginManager.view(PluginManager)) 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 |