Compare commits
No commits in common. "9dd5f5d4ad5c924dbcc617f5c2f93449436316a3" and "b3aa15b5804f0a32360e6f1d0d0fce13e66cd34f" have entirely different histories.
9dd5f5d4ad
...
b3aa15b580
@ -5,25 +5,15 @@ function shenv.quit()
|
||||
end
|
||||
shenv.cd = os.chdir
|
||||
shenv.mkdir = fs.makeDirectory
|
||||
local function findPath(name)
|
||||
path = os.getenv("PATH") or "/boot/exec"
|
||||
for l in path:gmatch("[^\n]+") do
|
||||
if fs.exists(l.."/"..name) then
|
||||
return l.."/"..name
|
||||
elseif fs.exists(l.."/"..name..".lua") then
|
||||
return l.."/"..name..".lua"
|
||||
end
|
||||
end
|
||||
end
|
||||
setmetatable(shenv,{__index=function(_,k)
|
||||
local fp = findPath(k)
|
||||
if _G[k] then
|
||||
return _G[k]
|
||||
elseif fp then
|
||||
elseif fs.exists("/boot/exec/"..k..".lua") then
|
||||
--[[
|
||||
local rqid = string.format("shell-%d",math.random(1,99999))
|
||||
return function(...)
|
||||
local tA = {...}
|
||||
local pid = os.spawn(function() computer.pushSignal(rqid,pcall(loadfile(fp),table.unpack(tA))) end,fp)
|
||||
local pid = os.spawn(function() computer.pushSignal(rqid,pcall(loadfile("/boot/exec/"..k..".lua"),table.unpack(tA))) end,"/boot/exec/"..k..".lua")
|
||||
local tE = {}
|
||||
repeat
|
||||
tE = {coroutine.yield()}
|
||||
@ -34,19 +24,17 @@ setmetatable(shenv,{__index=function(_,k)
|
||||
end
|
||||
return table.unpack(tE)
|
||||
end
|
||||
until not os.taskInfo(pid)
|
||||
until tTasks[pid] == nil
|
||||
end
|
||||
]]--
|
||||
return loadfile("/boot/exec/"..k..".lua")
|
||||
end
|
||||
end})
|
||||
print(_VERSION)
|
||||
os.setenv("run",true)
|
||||
while os.getenv("run") do
|
||||
io.write(string.format("%s:%s> ",os.getenv("HOSTNAME") or "localhost",(os.getenv("PWD") or _VERSION)))
|
||||
local input=io.read()
|
||||
if input:sub(1,1) == "=" then
|
||||
input = "return "..input:sub(2)
|
||||
end
|
||||
tResult = {pcall(load(input,"shell","t",shenv))}
|
||||
io.write((os.getenv("PWD") or _VERSION).."> ")
|
||||
tResult = {pcall(load(io.read(),"shell","t",shenv))}
|
||||
if tResult[1] == true then table.remove(tResult,1) end
|
||||
for k,v in pairs(tResult) do
|
||||
print(v)
|
||||
|
106
lib/unionfs.lua
106
lib/unionfs.lua
@ -1,106 +0,0 @@
|
||||
local unionfs = {}
|
||||
|
||||
local function normalise(path)
|
||||
return table.concat(fs.segments(path),"/")
|
||||
end
|
||||
|
||||
function unionfs.create(...)
|
||||
local paths,fids,fc = {...}, {}, 0
|
||||
for k,v in pairs(paths) do
|
||||
paths[k] = "/"..normalise(v)
|
||||
end
|
||||
local proxy = {}
|
||||
local function realpath(path)
|
||||
path = path or ""
|
||||
for k,v in pairs(paths) do
|
||||
if fs.exists(v.."/"..path) then
|
||||
return v.."/"..path
|
||||
end
|
||||
end
|
||||
return paths[1].."/"..path
|
||||
end
|
||||
|
||||
function proxy.spaceUsed()
|
||||
return fs.spaceUsed(paths[1])
|
||||
end
|
||||
function proxy.spaceTotal()
|
||||
return fs.spaceTotal(paths[1])
|
||||
end
|
||||
function proxy.isReadOnly()
|
||||
return fs.isReadOnly(paths[1])
|
||||
end
|
||||
function proxy.isDirectory(path)
|
||||
return fs.isDirectory(realpath(path))
|
||||
end
|
||||
function proxy.lastModified(path)
|
||||
return fs.lastModified(realpath(path))
|
||||
end
|
||||
|
||||
function proxy.exists(path)
|
||||
return fs.exists(realpath(path))
|
||||
end
|
||||
function proxy.remove(path)
|
||||
return fs.remove(realpath(path))
|
||||
end
|
||||
function proxy.size(path)
|
||||
return fs.size(realpath(path))
|
||||
end
|
||||
|
||||
function proxy.list(path)
|
||||
local nt,rt = {},{}
|
||||
if #fs.segments(path) < 1 then
|
||||
for k,v in pairs(paths) do
|
||||
print(v.."/"..path)
|
||||
for l,m in ipairs(fs.list(v.."/"..path)) do
|
||||
nt[m] = true
|
||||
end
|
||||
end
|
||||
for k,v in pairs(nt) do
|
||||
rt[#rt+1] = k
|
||||
end
|
||||
table.sort(rt)
|
||||
return rt
|
||||
else
|
||||
return fs.list(realpath(path))
|
||||
end
|
||||
end
|
||||
|
||||
function proxy.open(path,mode)
|
||||
local fh, r = fs.open(realpath(path),mode)
|
||||
if not fh then return fh, r end
|
||||
fids[fc] = fh
|
||||
fc = fc + 1
|
||||
return fc - 1
|
||||
end
|
||||
|
||||
function proxy.close(fid)
|
||||
if not fids[fid] then
|
||||
return false, "file not open"
|
||||
end
|
||||
local rfh = fids[fid]
|
||||
fids[fid] = nil
|
||||
return rfh:close()
|
||||
end
|
||||
function proxy.write(fid,d)
|
||||
if not fids[fid] then
|
||||
return false, "file not open"
|
||||
end
|
||||
return fids[fid]:write(d)
|
||||
end
|
||||
function proxy.read(fid,d)
|
||||
if not fids[fid] then
|
||||
return false, "file not open"
|
||||
end
|
||||
return fids[fid]:read(d)
|
||||
end
|
||||
function proxy.seek(fid,d)
|
||||
if not fids[fid] then
|
||||
return false, "file not open"
|
||||
end
|
||||
return fids[fid]:seek(d)
|
||||
end
|
||||
|
||||
return proxy
|
||||
end
|
||||
|
||||
return unionfs
|
Loading…
Reference in New Issue
Block a user