ACTUALLY added overwriting package data if it is the same length. Whoops.

This commit is contained in:
2026-05-03 15:55:58 +03:00
parent 4bc3a64a8c
commit e001c1b17e
+24 -3
View File
@@ -93,10 +93,30 @@ function solvitdb.set(path, name, data)
checkArg(3, data, "table") checkArg(3, data, "table")
local readHandle, patLength = checkValidityAndOpen(path) local readHandle, patLength = checkValidityAndOpen(path)
local pat = readPat(readHandle, patLength) local pat = readPat(readHandle, patLength)
local writeHandle = assert(fs.open(path, "a"))
if pat[name] then if pat[name] then
handle:seek(pat[name])
local data, tmpdata = ""
repeat
tmpdata = readHandle:read(math.huge)
oldData = oldData .. (tmpdata or "")
until oldData:find("\n", 1, true) or not tmpdata
readHandle:close()
if not oldData:find("\n", 1, true) and not tmpdata then
error("hit unexpected EOF")
end
oldData = oldData:match("^[^\n]+")
local difference = #data - #oldData
if difference == 0 then
writeHandle:seek("set", pat[name] + patLength + 8)
readHandle:close()
writeHandle:write(data)
elseif difference < 0 then
elseif difference > 0 then
end
else else
local writeHandle = assert(fs.open(path, "a"))
writeHandle:seek("end") writeHandle:seek("end")
local newPackageLocation = writeHandle:seek() - patLength - 8 local newPackageLocation = writeHandle:seek() - patLength - 8
if newPackageLocation > 4294967295 then if newPackageLocation > 4294967295 then
@@ -107,6 +127,7 @@ function solvitdb.set(path, name, data)
writeHandle:seek("set", patLength + 8) -- + 8 because that's the length of the header writeHandle:seek("set", patLength + 8) -- + 8 because that's the length of the header
local patData = ("%s.%s;"):format(name, string.pack("<I4", newPackageLocation)) local patData = ("%s.%s;"):format(name, string.pack("<I4", newPackageLocation))
insert(readHandle, writeHandle, patData) insert(readHandle, writeHandle, patData)
readHandle:close()
local newPatLength = patLength + #patData local newPatLength = patLength + #patData
writeHandle:seek("set", 0) writeHandle:seek("set", 0)
if newPatLength > 4294967295 then if newPatLength > 4294967295 then
@@ -131,10 +152,11 @@ function solvitdb.get(path, name)
tmpdata = handle:read(math.huge) tmpdata = handle:read(math.huge)
data = data .. (tmpdata or "") data = data .. (tmpdata or "")
until data:find("\n", 1, true) or not tmpdata until data:find("\n", 1, true) or not tmpdata
handle:close()
if not data:find("\n", 1, true) and not tmpdata then if not data:find("\n", 1, true) and not tmpdata then
error("hit unexpected EOF") error("hit unexpected EOF")
end end
data = data:match("^(.-)\n") data = data:match("^[^\n]+")
local output = {} local output = {}
if data:sub(1, 1) == "P" then if data:sub(1, 1) == "P" then
output.type = "package" output.type = "package"
@@ -167,7 +189,6 @@ function solvitdb.get(path, name)
table.insert(seriesOutput, seriesItem) table.insert(seriesOutput, seriesItem)
end end
end end
handle:close()
return output return output
end end