From 9983acb2677539654a89006971d18b565c86dcc2 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Sat, 6 Jun 2020 20:24:15 +1000 Subject: [PATCH] clean up pkgman.upgrade --- lib/pkgman.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/pkgman.lua b/lib/pkgman.lua index 0f7f237..eaf193c 100644 --- a/lib/pkgman.lua +++ b/lib/pkgman.lua @@ -4,6 +4,7 @@ local pkg = {} pkg.cfgPath = "/boot/cfg/pkg" pkg.sourcePath = pkg.cfgPath .. "/sources.cfg" pkg.installedPath = pkg.cfgPath .. "/installed.cfg" +require("pkgfs") local function getSources() local f = io.open(pkg.sourcePath,"rb") @@ -126,13 +127,12 @@ function pkg.upgrade(force) -- boolean -- boolean -- Upgrades all packages on th fs.makeDirectory("/boot/pkg") local installed = getInstalled() for repo,info in pairs(getSources()) do - for pkgname,pkg in pairs(getRepoMeta(repo)) do - if pkg.version ~= installed[pkgname].version or force then + for pkgname,pkginfo in pairs(getRepoMeta(repo)) do + if installed[pkgname] and pkginfo.version ~= installed[pkgname].version or force then pkg.remove(pkgname) - dl(info.path.."/"..pkg.filename,"/boot/pkg/"..pkg.filename) + dl(info.path.."/"..pkginfo.filename,"/boot/pkg/"..pkginfo.filename) installed[pkgname] = pkg - pcall(activatePackage,"/boot/pkg/"..pkg.filename,pkg.compressed) - return true + pcall(activatePackage,"/boot/pkg/"..pkginfo.filename,pkginfo.compressed) end end end @@ -142,7 +142,7 @@ end function pkg.remove(pkgname) -- string -- boolean -- Remove the package *pkgname* from the pkgfs and package directory. local installed = getInstalled() local pkginfo = installed[pkgname] - if not pkginfo then error(pkgname .." not installed") end + if not pkginfo then return true end pcall(deactivatePackage,"/boot/pkg/"..pkginfo.filename) fs.remove("/boot/pkg/"..pkginfo.filename) installed[pkgname] = nil