Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions core/xim/CmdProcessor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function CmdProcessor:run_target_cmds()
local pkg = index_manager:load_package(target_pkgname)
self._pm_executor = pm_service:create_pm_executor(pkg)
self.target = target_pkgname
self._input_target = input_target -- backup

if self.cmds.info_json then
local pkginfo = self._pm_executor._pkg:info()
Expand Down Expand Up @@ -196,6 +197,8 @@ function CmdProcessor:run_nontarget_cmds()
-- target is nil
if self.cmds.list then
self:list()
elseif self.cmds.update then
self:update()
elseif self.cmds.sysdetect then
self:sys_detect()
elseif self.cmds.sysupdate then
Expand Down Expand Up @@ -336,7 +339,20 @@ function CmdProcessor:remove()
end

function CmdProcessor:update()
cprint("[xlings:xim]: update not implement")
cprint("[xlings:xim]: ${dim bright}sync repo and rebuild index...${clear}")

index_manager:sync_repo()
index_manager:rebuild()
self:sys_detect()

-- TODO: support install latest version for target
if self._input_target and self._input_target ~= "" then
cprint("[xlings:xim]: ${bright}try to update [ %s ] to latest version...${clear}", self._input_target)
new(self._input_target .. "@latest", {
yes = true,
disable_info = true
}):run()
end
end

function CmdProcessor:sys_detect()
Expand All @@ -360,7 +376,7 @@ end
function CmdProcessor:sys_update()
local datadir = runtime.get_xim_data_dir()
if self.cmds.sysupdate == "index" then
index_manager:sync_repo()
index_manager:sync_repo(true)
index_manager:rebuild()
self:sys_detect()
elseif self.cmds.sysupdate == "self" then
Expand Down
4 changes: 2 additions & 2 deletions core/xim/index/IndexManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ function IndexManager:update()
IndexManager.status_changed_pkg = {}
end

function IndexManager:sync_repo()
repo_manager:sync()
function IndexManager:sync_repo(force)
repo_manager:sync(force)
end

function IndexManager:rebuild()
Expand Down
26 changes: 24 additions & 2 deletions core/xim/index/RepoManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ RepoManager.__index = RepoManager
function new()
local config = xconfig.load()
RepoManager.repo = config.xim["index-repo"]
RepoManager.updateSchedule = 30 -- days
RepoManager.updateSchedule = 7 -- days
return RepoManager
end

function RepoManager:sync()
function RepoManager:sync(force)

if not self:need_to_update(force) then
cprint("[xlings: xim]: ${dim}skip sync indexrepos, not reach update schedule(use `xim --update index` to force)...")
return
end

cprint("[xlings: xim]: sync indexrepos...")

Expand Down Expand Up @@ -135,6 +140,23 @@ function RepoManager:add_subrepo(namespace, repo)
return _to_repodir(repo, index_reposdir)
end

function RepoManager:need_to_update(force)
local last_update_file = path.join(data_dir, "xim_last_update_time")
if force or (not os.isfile(last_update_file)) then
io.writefile(last_update_file, tostring(os.time()))
return true
else
local last_update_time = tonumber(io.readfile(last_update_file))
local current_time = os.time()
local delta_days = (current_time - last_update_time) / (24 * 3600)
if delta_days >= RepoManager.updateSchedule then
io.writefile(last_update_file, tostring(current_time))
return true
end
end
return false
end

function _sync_repo(repo, rootdir)
cprint("[xlings: xim]: sync package index repo: ${dim green}%s", repo)

Expand Down
2 changes: 2 additions & 0 deletions core/xlings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ function main()
_command_dispatch(d2x, "checker", cmd_target, cmd_args)
elseif command == "remove" then
_command_dispatch(xinstall, "-r", cmd_target, cmd_args)
elseif command == "update" then
_command_dispatch(xinstall, "-u", cmd_target, cmd_args)
elseif command == "config" then
config_llm()
else -- submodule
Expand Down
Loading