2022-12-03 22:31:21 +08:00
|
|
|
local Config = require("lazy.core.config")
|
2023-10-09 17:25:42 +08:00
|
|
|
local Util = require("lazy.util")
|
2022-11-29 05:03:44 +08:00
|
|
|
|
|
|
|
---@type table<string, LazyTaskDef>
|
|
|
|
local M = {}
|
|
|
|
|
2024-06-24 20:27:29 +08:00
|
|
|
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
|
|
|
|
|
2022-11-29 05:03:44 +08:00
|
|
|
M.clean = {
|
2022-12-03 22:31:21 +08:00
|
|
|
skip = function(plugin)
|
|
|
|
return plugin._.is_local
|
|
|
|
end,
|
2024-07-08 13:45:43 +08:00
|
|
|
---@param opts? {rocks_only?:boolean}
|
|
|
|
run = function(self, opts)
|
|
|
|
opts = opts or {}
|
2022-11-29 05:03:44 +08:00
|
|
|
local dir = self.plugin.dir:gsub("/+$", "")
|
2022-12-03 22:48:06 +08:00
|
|
|
assert(dir:find(Config.options.root, 1, true) == 1, self.plugin.dir .. " should be under packpath!")
|
2022-11-29 05:03:44 +08:00
|
|
|
|
2024-06-24 20:27:29 +08:00
|
|
|
local rock_root = Config.options.rocks.root .. "/" .. self.plugin.name
|
|
|
|
if vim.uv.fs_stat(rock_root) then
|
|
|
|
rm(rock_root)
|
|
|
|
end
|
2022-12-03 22:31:21 +08:00
|
|
|
|
2024-07-08 13:45:43 +08:00
|
|
|
if opts.rocks_only then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
rm(dir)
|
|
|
|
|
2022-12-03 22:31:21 +08:00
|
|
|
self.plugin._.installed = false
|
2022-11-29 05:03:44 +08:00
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
return M
|