1
1
mirror of https://git.shadowkat.net/izaya/OC-PsychOS2.git synced 2024-11-25 12:42:10 -05:00

rewrote the whole index thing and made it possible to remove packages from the pkgfs index

This commit is contained in:
XeonSquared 2020-06-06 13:35:59 +10:00
parent 3266c66fc4
commit 999d8e0387

View File

@ -3,6 +3,7 @@ local w, lz16 = pcall(require, "liblz16")
if not w then lz16 = nil end if not w then lz16 = nil end
pkgfs = {} pkgfs = {}
pkgfs.files = {}
local findex = {} local findex = {}
local handles = {} local handles = {}
local hc = 0 local hc = 0
@ -98,17 +99,35 @@ function pkgfs.component.close(handle)
return true return true
end end
function pkgfs.add(fname,comp) -- string boolean -- -- Add a package as specified in *fname* to the pkgfs component. If *comp* is true, read it as a LZ16-compressed package. local function index()
findex = {}
for k,v in pairs(pkgfs.files) do
fname, comp = v[1], v[2]
if fname:sub(1,1) ~= "/" then if fname:sub(1,1) ~= "/" then
fname = "/"..fnormalize(os.getenv("PWD").."/"..fname) fname = "/"..fnormalize(os.getenv("PWD").."/"..fname)
end end
local f = fopen(fname,comp) local f = fopen(fname,comp)
if not fname then error("unable to open file") end if not f then error("unable to open file") end
print(fname) print(fname)
for name, read, fsize in mtar.iter(f) do for name, read, fsize in mtar.iter(f) do
findex[fnormalize(name)] = {fname,comp} findex[fnormalize(name)] = {fname,comp}
end end
f:close() f:close()
end
return true
end
function pkgfs.add(fname,comp) -- string boolean -- boolean -- Add a package as specified in *fname* to the pkgfs component. If *comp* is true, read it as a LZ16-compressed package.
pkgfs.files[#pkgfs.files+1] = {fname,comp}
return index()
end
function pkgfs.remove(fname) -- string -- boolean -- Removes the package specified by *fname* from the pkgfs index.
for k,v in pairs(pkgfs.files) do
if v[1] == fname then
table.remove(pkgfs.files,k)
end
end
return index()
end end
fs.makeDirectory("/pkg") fs.makeDirectory("/pkg")