move clean() to the fs file
This commit is contained in:
44
lua/dep.lua
44
lua/dep.lua
@ -49,46 +49,6 @@ function M.registertree(speclist, overrides)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- clean out old packages
|
|
||||||
function M.clean()
|
|
||||||
h.uv.fs_scandir(
|
|
||||||
packager.get_base_dir(),
|
|
||||||
vim.schedule_wrap(function(err, handle)
|
|
||||||
if err then
|
|
||||||
logger:log("error", "failed to clean; reason: %s", err)
|
|
||||||
else
|
|
||||||
local queue = {}
|
|
||||||
|
|
||||||
while handle do
|
|
||||||
local name = h.uv.fs_scandir_next(handle)
|
|
||||||
if name then
|
|
||||||
queue[name] = packager.get_base_dir().."/"..name
|
|
||||||
else
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- keep packages that still exist
|
|
||||||
for _, package in pairs(packager.get_packages()) do
|
|
||||||
queue[package.name] = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
for name, dir in pairs(queue) do
|
|
||||||
local co = coroutine.create(function()
|
|
||||||
local ok = vim.fn.delete(dir, "rf")
|
|
||||||
if ok then
|
|
||||||
logger:log("clean", "deleted %s", name)
|
|
||||||
else
|
|
||||||
logger:log("error", "failed to delete %s", name)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
coroutine.resume(co)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
--- reload all packages in package table spec
|
--- reload all packages in package table spec
|
||||||
---@param force boolean? force all packages to load
|
---@param force boolean? force all packages to load
|
||||||
function M.reload(force)
|
function M.reload(force)
|
||||||
@ -131,7 +91,7 @@ function M.synctree(tree, cb)
|
|||||||
logger:log("update", "synchronized %s %s", #tree, #tree == 1 and "package" or "packages")
|
logger:log("update", "synchronized %s %s", #tree, #tree == 1 and "package" or "packages")
|
||||||
end
|
end
|
||||||
|
|
||||||
M.clean()
|
fs:clean(packager)
|
||||||
M.reload()
|
M.reload()
|
||||||
|
|
||||||
if cb then
|
if cb then
|
||||||
@ -257,7 +217,7 @@ return function(opts)
|
|||||||
|
|
||||||
vim.api.nvim_create_user_command("DepClean", function()
|
vim.api.nvim_create_user_command("DepClean", function()
|
||||||
-- clean AND reload to make sure that all old packages are gone
|
-- clean AND reload to make sure that all old packages are gone
|
||||||
M.clean()
|
fs:clean(packager)
|
||||||
M.reload()
|
M.reload()
|
||||||
end, {})
|
end, {})
|
||||||
|
|
||||||
|
@ -19,4 +19,45 @@ function fs:link(package, cb)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- clean out old packages
|
||||||
|
---@param package package any package
|
||||||
|
function fs:clean(package)
|
||||||
|
h.uv.fs_scandir(
|
||||||
|
package.get_base_dir(),
|
||||||
|
vim.schedule_wrap(function(err, handle)
|
||||||
|
if err then
|
||||||
|
logger:log("error", "failed to clean; reason: %s", err)
|
||||||
|
else
|
||||||
|
local queue = {}
|
||||||
|
|
||||||
|
while handle do
|
||||||
|
local name = h.uv.fs_scandir_next(handle)
|
||||||
|
if name then
|
||||||
|
queue[name] = package.get_base_dir().."/"..name
|
||||||
|
else
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- keep packages that still exist
|
||||||
|
for _, pkg in pairs(package.get_packages()) do
|
||||||
|
queue[pkg.name] = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
for name, dir in pairs(queue) do
|
||||||
|
local co = coroutine.create(function()
|
||||||
|
local ok = vim.fn.delete(dir, "rf")
|
||||||
|
if ok then
|
||||||
|
logger:log("clean", "deleted %s", name)
|
||||||
|
else
|
||||||
|
logger:log("error", "failed to delete %s", name)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
coroutine.resume(co)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
return fs
|
return fs
|
||||||
|
Reference in New Issue
Block a user