Skip to content

Commit

Permalink
fix(luarocks): cleanup luarocks when deleting a plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jun 24, 2024
1 parent 368747b commit b73c57e
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions lua/lazy/manage/task/fs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,32 @@ local Util = require("lazy.util")
---@type table<string, LazyTaskDef>
local M = {}

local function rm(dir)
local stat = vim.uv.fs_lstat(dir)
assert(stat and stat.type == "directory", dir .. " should be a directory!")
Util.walk(dir, function(path, _, type)
if type == "directory" then
vim.uv.fs_rmdir(path)
else
vim.uv.fs_unlink(path)
end
end)
vim.uv.fs_rmdir(dir)
end

M.clean = {
skip = function(plugin)
return plugin._.is_local
end,
run = function(self)
local dir = self.plugin.dir:gsub("/+$", "")
assert(dir:find(Config.options.root, 1, true) == 1, self.plugin.dir .. " should be under packpath!")
rm(dir)

local stat = vim.uv.fs_lstat(dir)
assert(stat and stat.type == "directory", self.plugin.dir .. " should be a directory!")

Util.walk(dir, function(path, _, type)
if type == "directory" then
vim.uv.fs_rmdir(path)
else
vim.uv.fs_unlink(path)
end
end)
vim.uv.fs_rmdir(dir)
local rock_root = Config.options.rocks.root .. "/" .. self.plugin.name
if vim.uv.fs_stat(rock_root) then
rm(rock_root)
end

self.plugin._.installed = false
end,
Expand Down

0 comments on commit b73c57e

Please sign in to comment.