solvit: added some support for constant versions

This commit is contained in:
Ponali
2026-05-03 19:06:06 +02:00
parent f275247b00
commit 60283fc40e
+27 -18
View File
@@ -1,6 +1,8 @@
local defaultDBPath = "/ag2/testdb.json"
local fs = require("filesystem")
-- local db = require("solvitdb") -- local db = require("solvitdb")
local db = {} local db = {}
local fs = require("filesystem")
local json = require("json") local json = require("json")
function db.create(dbpath) function db.create(dbpath)
local handle = fs.open(dbpath,"w") local handle = fs.open(dbpath,"w")
@@ -176,7 +178,7 @@ local function removeFromArray(el,arr)
end end
local function startTransaction(dbpath) local function startTransaction(dbpath)
dbpath = dbpath or "/ag2/testdb.json" dbpath = dbpath or defaultDBPath
if not fs.exists(dbpath) then if not fs.exists(dbpath) then
db.create(dbpath) db.create(dbpath)
end end
@@ -203,6 +205,7 @@ local function startTransaction(dbpath)
function transaction.updateAll(name) function transaction.updateAll(name)
end end
function transaction.addInfo(name,info) function transaction.addInfo(name,info)
if not info.type then info.type="package" end
packInfo[name]=info packInfo[name]=info
-- print(require("serialize").table(packInfo)) -- print(require("serialize").table(packInfo))
end end
@@ -264,12 +267,12 @@ local function startTransaction(dbpath)
local dat = getPackInfo(rem[i]) local dat = getPackInfo(rem[i])
if dat.reverseDependencies and #dat.reverseDependencies>0 then if dat.reverseDependencies and #dat.reverseDependencies>0 then
for _,dep in ipairs(dat.reverseDependencies) do for _,dep in ipairs(dat.reverseDependencies) do
if not packageInArray(avs.parse(dep),rem) then if not packageInArray({dep},rem) then
if settings.cascade then if settings.cascade then
table.insert(rem,1,avs.parse(dep)) table.insert(rem,1,{dep})
i=i+1 i=i+1
else else
return false, "Package "..avs.serializePack(rem[i]).." is a dependency of "..dep return false, "Package "..rem[i][1].." is a dependency of "..dep
end end
end end
end end
@@ -286,10 +289,10 @@ local function startTransaction(dbpath)
local dep = avs.parse(deps[j]) local dep = avs.parse(deps[j])
local depdat = packInfo[deps[j]] local depdat = packInfo[deps[j]]
if not depdat then if not depdat then
depdat = db.get(dbpath,deps[j]) depdat = db.get(dbpath,dep[1])
packInfo[deps[j]]=depdat packInfo[deps[j]]=depdat
end end
if (not packageInArray(dep,rem)) and type(db.get(dbpath,dep[1]))~="nil" and (#depdat.reverseDependencies==1 and depdat.reverseDependencies[1]==avs.serializePack(rem[i])) then if (not packageInArray(dep,rem)) and type(db.get(dbpath,dep[1]))~="nil" and (#depdat.reverseDependencies==1 and depdat.reverseDependencies[1]==rem[i][1]) then
removeIncomplete=true removeIncomplete=true
table.insert(rem,j,dep) table.insert(rem,j,dep)
end end
@@ -327,8 +330,8 @@ local function startTransaction(dbpath)
-- return "true, {["install"] = {"dep1", "package1", "package2"}, ["remove"] = {"package3"}}" on success -- return "true, {["install"] = {"dep1", "package1", "package2"}, ["remove"] = {"package3"}}" on success
-- return "false, {"dep1"}" when not enough data -- return "false, {"dep1"}" when not enough data
-- return "false, "[verbose string]"" when conflict found -- return "false, "[verbose string]"" when conflict found
-- TODO: handle same constant AVS -- TODO: handle different constant AVS conflict (package1->dep1=1.0.0 + package2->dep1=1.2.3 where both are uninstalled)
-- TODO: handle different constant AVS conflict -- TODO: handle different constant AVS conflict (package1->dep1=1.0.0 + package2->dep1=1.2.3 where package2 is on db)
-- TODO: handle same range AVS -- TODO: handle same range AVS
-- TODO: handle different intercompatible 1.*.* range AVS -- TODO: handle different intercompatible 1.*.* range AVS
-- TODO: handle different incompatible 1.*.* range AVS -- TODO: handle different incompatible 1.*.* range AVS
@@ -350,25 +353,30 @@ local function startTransaction(dbpath)
local function storeInstall() local function storeInstall()
-- directly set -- directly set
for _,pack in ipairs(ins) do for _,pack in ipairs(ins) do
if packInfo[pack[1]] then if getPackInfo(pack) then
local info = table.copy(packInfo[pack[1]]) local info = table.copy(getPackInfo(pack))
info.version=pack[2] if pack[2] then
info.version=avs.serializeVersion(pack[2])
else
info.version=info.latestVersion or info.version
end
db.set(dbpath,pack[1],info) db.set(dbpath,pack[1],info)
end end
end end
-- set reverse dependencies -- set reverse dependencies
for _,pack in pairs(ins) do for _,pack in pairs(ins) do
local i = pack[1] local i = avs.serializePack(pack)
local v = packInfo[i] local v = packInfo[i]
if v and v.dependencies then if v and v.dependencies then
for _,dep in ipairs(v.dependencies) do for _,dep in ipairs(v.dependencies) do
local dat = db.get(dbpath,dep) local depname = avs.parse(dep)[1]
local dat = db.get(dbpath,depname)
if not dat then goto continue end if not dat then goto continue end
if type(dat.reverseDependencies)~="table" then if type(dat.reverseDependencies)~="table" then
dat.reverseDependencies={} dat.reverseDependencies={}
end end
table.insert(dat.reverseDependencies,i) table.insert(dat.reverseDependencies,pack[1])
db.set(dbpath,dep,dat) db.set(dbpath,depname,dat)
::continue:: ::continue::
end end
end end
@@ -384,11 +392,12 @@ local function startTransaction(dbpath)
local pdat = getPackInfo(pack) local pdat = getPackInfo(pack)
if not pdat.dependencies then goto continue end if not pdat.dependencies then goto continue end
for _,dep in ipairs(pdat.dependencies) do for _,dep in ipairs(pdat.dependencies) do
local dat = db.get(dbpath,dep) local depname = avs.parse(dep)[1]
local dat = db.get(dbpath,depname)
if dat.reverseDependencies then if dat.reverseDependencies then
removeFromArray(pack[1],dat.reverseDependencies) removeFromArray(pack[1],dat.reverseDependencies)
end end
db.set(dbpath,dep,dat) db.set(dbpath,depname,dat)
end end
::continue:: ::continue::
end end