clean up pkgman.upgrade

This commit is contained in:
Izaya 2020-06-06 20:24:15 +10:00
parent 6a39fe1743
commit 9983acb267

View File

@ -4,6 +4,7 @@ local pkg = {}
pkg.cfgPath = "/boot/cfg/pkg" pkg.cfgPath = "/boot/cfg/pkg"
pkg.sourcePath = pkg.cfgPath .. "/sources.cfg" pkg.sourcePath = pkg.cfgPath .. "/sources.cfg"
pkg.installedPath = pkg.cfgPath .. "/installed.cfg" pkg.installedPath = pkg.cfgPath .. "/installed.cfg"
require("pkgfs")
local function getSources() local function getSources()
local f = io.open(pkg.sourcePath,"rb") 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") fs.makeDirectory("/boot/pkg")
local installed = getInstalled() local installed = getInstalled()
for repo,info in pairs(getSources()) do for repo,info in pairs(getSources()) do
for pkgname,pkg in pairs(getRepoMeta(repo)) do for pkgname,pkginfo in pairs(getRepoMeta(repo)) do
if pkg.version ~= installed[pkgname].version or force then if installed[pkgname] and pkginfo.version ~= installed[pkgname].version or force then
pkg.remove(pkgname) pkg.remove(pkgname)
dl(info.path.."/"..pkg.filename,"/boot/pkg/"..pkg.filename) dl(info.path.."/"..pkginfo.filename,"/boot/pkg/"..pkginfo.filename)
installed[pkgname] = pkg installed[pkgname] = pkg
pcall(activatePackage,"/boot/pkg/"..pkg.filename,pkg.compressed) pcall(activatePackage,"/boot/pkg/"..pkginfo.filename,pkginfo.compressed)
return true
end end
end end
end end
@ -142,7 +142,7 @@ end
function pkg.remove(pkgname) -- string -- boolean -- Remove the package *pkgname* from the pkgfs and package directory. function pkg.remove(pkgname) -- string -- boolean -- Remove the package *pkgname* from the pkgfs and package directory.
local installed = getInstalled() local installed = getInstalled()
local pkginfo = installed[pkgname] 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) pcall(deactivatePackage,"/boot/pkg/"..pkginfo.filename)
fs.remove("/boot/pkg/"..pkginfo.filename) fs.remove("/boot/pkg/"..pkginfo.filename)
installed[pkgname] = nil installed[pkgname] = nil