forked from izaya/OC-PsychOS2
rewrote the whole index thing and made it possible to remove packages from the pkgfs index
This commit is contained in:
parent
3266c66fc4
commit
999d8e0387
@ -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,18 +99,36 @@ 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
|
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
|
||||||
|
|
||||||
fs.makeDirectory("/pkg")
|
fs.makeDirectory("/pkg")
|
||||||
fs.mount("/pkg",pkgfs.component)
|
fs.mount("/pkg",pkgfs.component)
|
||||||
|
Loading…
Reference in New Issue
Block a user