add pkgfs.component.exists and do automounting of archives

This commit is contained in:
Izaya 2020-06-06 19:45:40 +10:00
parent 4e3df481cc
commit f86f7d54ad

View File

@ -15,7 +15,7 @@ local function rzero()
return 0 return 0
end end
pkgfs.component = {seek = rfalse, makeDirectory = rfalse, write = rfalse, rename = rfalse, setlabel = rfalse, spaceUsed = rzero, spaceTotal = rzero, lastModified = rzero} pkgfs.component = {seek = rfalse, makeDirectory = rfalse, write = rfalse, rename = rfalse, setlabel = rfalse, spaceUsed = rzero, spaceTotal = rzero, lastModified = rzero, address = "pkgfs"}
local function fopen(path,comp) local function fopen(path,comp)
local f local f
@ -31,6 +31,11 @@ local function fnormalize(s)
return table.concat(fs.segments(s),"/") return table.concat(fs.segments(s),"/")
end end
function pkgfs.component.exists(path)
path = fnormalize(path)
return findex[path] and true
end
function pkgfs.component.list(path) function pkgfs.component.list(path)
path = fnormalize(path).."/" path = fnormalize(path).."/"
local ft,rt = {},{} local ft,rt = {},{}
@ -107,8 +112,7 @@ local function index()
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 f then error("unable to open file") end if not f then error("unable to open file "..fname) end
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
@ -132,4 +136,11 @@ end
fs.makeDirectory("/pkg") fs.makeDirectory("/pkg")
fs.mount("/pkg",pkgfs.component) fs.mount("/pkg",pkgfs.component)
for _,file in ipairs(fs.list("/boot/pkg/")) do
if file:sub(-5) == ".mtar" then
pcall(pkgfs.add,"/boot/pkg/"..file)
elseif file:sub(-9) == ".mtar.lss" then
pcall(pkgfs.add,"/boot/pkg/"..file,true)
end
end
return pkgfs return pkgfs