From e001c1b17e98de63b1e53794406a543e9cadf631 Mon Sep 17 00:00:00 2001 From: WahPlus Date: Sun, 3 May 2026 15:55:58 +0300 Subject: [PATCH] ACTUALLY added overwriting package data if it is the same length. Whoops. --- lib/solvitdb.lua | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/solvitdb.lua b/lib/solvitdb.lua index 4f7181e..9be6e3c 100644 --- a/lib/solvitdb.lua +++ b/lib/solvitdb.lua @@ -93,10 +93,30 @@ function solvitdb.set(path, name, data) checkArg(3, data, "table") local readHandle, patLength = checkValidityAndOpen(path) local pat = readPat(readHandle, patLength) + local writeHandle = assert(fs.open(path, "a")) 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 - local writeHandle = assert(fs.open(path, "a")) writeHandle:seek("end") local newPackageLocation = writeHandle:seek() - patLength - 8 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 local patData = ("%s.%s;"):format(name, string.pack(" 4294967295 then @@ -131,10 +152,11 @@ function solvitdb.get(path, name) tmpdata = handle:read(math.huge) data = data .. (tmpdata or "") until data:find("\n", 1, true) or not tmpdata + handle:close() if not data:find("\n", 1, true) and not tmpdata then error("hit unexpected EOF") end - data = data:match("^(.-)\n") + data = data:match("^[^\n]+") local output = {} if data:sub(1, 1) == "P" then output.type = "package" @@ -167,7 +189,6 @@ function solvitdb.get(path, name) table.insert(seriesOutput, seriesItem) end end - handle:close() return output end