fix devfs a bit

This commit is contained in:
osmarks 2025-03-10 13:54:32 +00:00
parent 423f622271
commit 06a4fb6145
4 changed files with 30 additions and 18 deletions

View File

@ -17,6 +17,8 @@ Thanks to technology, we're able to offer a live PotatOS instance in your browse
<button id="launch-demo">Experience PotatOS</button>
<div id="computer"></div>
(if the emulator gets stuck, please refresh this page)
<noscript>
Experiencing PotatOS requires JavaScript. Please enable it.
</noscript>
@ -72,7 +74,7 @@ Unlike most "OS"es for CC (primarily excluding Opus OS, which is actually useful
- To ease large-scale network management, PotatOS's networking daemon turns on any networked potatOS computers.
- Improves connected signs, if Plethora Peripherals is installed.
- Recycle bin capability stops accidental loss of files.
- `exorcise` command, which is like delete but better.
- `exorcise` command, which is like `delete` but better.
- Support for a wide variety of Lorem Ipsum integrated into the OS.
- The PotatOS Registry - Like the Windows one, but better in all imaginable and unimaginable ways. Edit and view its contents with the `est` command.
- Window manager shipped. I forgot what it is and how to use it.

File diff suppressed because one or more lines are too long

View File

@ -33,24 +33,26 @@ function vfs.list(path)
end
return out
elseif #segs == 2 then
end
end
local function write_handle(callback)
local buffer = ""
local write_handle = {}
function write_handle.write(text)
local r_write_handle = {}
function r_write_handle.write(text)
buffer = buffer .. text
end
function write_handle.close()
function r_write_handle.close()
callback(buffer)
end
function write_handle.flush() end
function write_handle.writeLine(text) write_handle.write(text) write_handle.write("\n") end
return write_handle
function r_write_handle.flush() end
function r_write_handle.writeLine(text) r_write_handle.write(text) r_write_handle.write("\n") end
return r_write_handle
end
local call_results = {}
function vfs.open(path, mode)
local segs = fs.segment(path)
if #segs == 2 and segs[2]:match "^[A-Z]" then -- getter/setter configuration
@ -58,7 +60,7 @@ function vfs.open(path, mode)
return write_handle(function(buffer)
local ok, res
for _, s in pairs(setters) do
local ok2, res2 = pcall(peripheral.call, segs[1], s .. segs[2], json.decode(buffer))
local ok2, res2 = pcall(peripheral.call, segs[1], s .. segs[2], textutils.unserialise(buffer))
ok = ok or ok2
res = res or res2
end
@ -71,15 +73,24 @@ function vfs.open(path, mode)
local ok, res = pcall(peripheral.call, segs[1], g .. segs[2])
result = result or (ok and res)
end
local text = json.encode(result)
local text = textutils.serialise(result)
return fs._make_handle(text)
end
elseif #segs == 2 then
if mode:match "w" then
if mode:match "^w" then
return write_handle(function(buffer)
peripheral.call(segs[1], segs[2], json.decode(buffer))
call_results[fs.combine(path, "")] = peripheral.call(segs[1], segs[2], unpack(textutils.unserialise(buffer)))
end)
end
if mode:match "^r" then
local rp = fs.combine(path, "")
local h
if call_results[rp] then h = fs._make_handle(textutils.serialise(call_results[rp]))
else h = fs._make_handle("") end
call_results[rp] = nil
return h
end
error "invalid IO mode"
end
end
@ -114,4 +125,4 @@ function vfs.isDir(path)
end
function vfs.getDrive(path) return "devfs" end
fs.mountVFS(shell.resolve(...), vfs)
fs.mountVFS(shell.resolve(...), vfs)

View File

@ -47,8 +47,7 @@ local registry = require "registry"
--[[
Server Policy Framework
On 12/01/2020 CE (this is probably overprecise and I doubt anyone will care, yes), there was a weird incident on SwitchCraft involving some turtles somehow getting potatOS installed (seriously, "somehow" is accurate, I have no idea what caused this and attempted to uninstall it when someone actually pinged me; I think it involved a turtle getting set to ID 0 somehow, who knows how potatOS got onto ID 0 in the first place). In light of this (and it apparently breaking rule 9, despite this not having any involvement from me except for me remotely uninstalling it), SC's admins have demanded some features be disabled (EZCopy).
Since I don't really want to hardcode random SwitchCraft APIs deep in the code somewhere (it's worrying that they *have* specific ones, as it seems like some programs are being written specifically against them now - seems kind of EEE), and other people will inevitably demand their own special cases, I'm making what should be a reasonably generic way to handle this.
On 12/01/2020 CE (this is probably overprecise and I doubt anyone will care, yes), the ID 0 bug resulted in potatOS improving a large quantity of turtles, apparently causing problems. In light of this, SC's admins have demanded some features be disabled (EZCopy). This is a reasonably generic way to handle server-specific special cases.
]]
local SPF = {
@ -1457,7 +1456,7 @@ local function run_with_sandbox()
local debug_sentinel = sandboxlib.create_sentinel "constrained-debug"
local sandbox_filesystem = yafss.create_FS(vfstree)
_G.fs = sandboxlib.dispatch_if_restricted(fss_sentinel, _G.fs, sandbox_filesystem)
_G.debug = sandboxlib.allow_whitelisted(debug_sentinel, _G.debug, {
_G.debug = sandboxlib.allow_whitelisted(debug_sentinel, _G.debug or {}, {
"traceback",
"getinfo",
"getregistry"