From 06a4fb6145fda58add584bc7e34f1e4241de8d66 Mon Sep 17 00:00:00 2001 From: osmarks Date: Mon, 10 Mar 2025 13:54:32 +0000 Subject: [PATCH] fix devfs a bit --- README.md | 4 +++- manifest | 4 ++-- src/bin/devfs.lua | 35 +++++++++++++++++++++++------------ src/main.lua | 5 ++--- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index bad38ad..bef4b0d 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ Thanks to technology, we're able to offer a live PotatOS instance in your browse
+(if the emulator gets stuck, please refresh this page) + @@ -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. diff --git a/manifest b/manifest index 4142617..ba99bc9 100644 --- a/manifest +++ b/manifest @@ -1,2 +1,2 @@ -{"build":843,"description":"devfs test","files":{"LICENSES":"f3549d84d66eb53dd4a421a4341d77d3d217c1b117d67e3be8f5211adcda0952","autorun.lua":"fa150c1ea1d19a78e1b7f2e7051298e9a792bf6fb83b8ac3dd0c7276d123b79c","bin/5rot26.lua":"417891a232e325476f980d31d88edc486d526611a6350ce47fd29cca464ebf2c","bin/BSOD.lua":"a2ea9bf1e64dbc2c314e3be71f46e973c0bc2b9c482395120f5d152c6d231e86","bin/b.lua":"5123c6d1bb2b3d6c8e7b4d1b94e60d47c3b6c64c5a0fe8bda8481b718ba00602","bin/build.lua":"a990239e1db05176dd0ba56bc0179eecccd8473d88c6c618d16e72ede270e4c2","bin/ccemux.lua":"239476f58835b86bbcac31ce8af3c3acd3d198a55ab9ada78c62fbf358625a98","bin/chronometer.lua":"db5363993a04382145aef7db2fbe262f0bf10697a589e1e2d2f9ce0f87430dd8","bin/chuck.lua":"571a1eacde435bbd9f54b493149339ac48972a3a4550635b9107da0091fe888a","bin/clear_space.lua":"fc3d52563adaf0491b71227f8b6f615d604063a89830a2ab86a20d10e1a07e97","bin/ctime.lua":"c64022ef0ac641ea531567d770adb306d0d632ff7bd2b692f4915021ed6787c0","bin/devfs.lua":"24a65b7f9803b9ec7caa70be1d5f19b4832de5925f41266bf63665c4dde4b4c0","bin/est.lua":"88ab488c2ded31d67816da8c309a63ac455b461368b3b943aeeb5106b1051cc0","bin/exorcise.lua":"ae25e5939ce52620b0a1e64679a1ac47bcaaff9e323d29c6651bce24a3e58116","bin/factor.lua":"39c2f1709a4258d754278860177c7bb2ea336a8b8392a4c3017c849705e63926","bin/fortune.lua":"64a595afb9ffbaa39622b32379d8dc40d4f1fd36d38027382ed0ae130ad0c59d","bin/game_mode.lua":"f1519969a83e6c7c001d4092cbc7806ea489652ea19022425a893fb4d153572f","bin/grep.lua":"1509bc267867b933e528ab74cfbc2a15fa2df0ec7389df4f9033194ab9037865","bin/hacker.lua":"889e1a47c5ff7470ddf61d87eb7cca9750193976139d513fbe67b7625195d65a","bin/id.lua":"82131679ee35c705458660ac31ab4f5f90169b43f2377fe420a99b1d4c03a4dd","bin/init-screens.lua":"c586a7704030dc1917262f04350e094e1e0ab084793eb1643222498f6436b597","bin/intelligence.lua":"0f14f5a5fb2c6053c19c7a8fa0ba335a69a6fb3b49941c3234dac59795cd3850","bin/kristminer.lua":"7e7f9fe2a6493d584ad6926cda915e02c1c3d800dc209680898ce930d0bb0e6f","bin/livegps.lua":"c3d17d495cda01aa1261e4c4fcd43439b29af422671972117ec34f68e32c5bba","bin/lmatrix.lua":"9d5728b93069d2b763bb8e1dd2a5542995c47daca61f385644431bfc315bc2c4","bin/loading.lua":"c85f7aa1765170325155b921c1fceeb62643f552f12d41b529a22af3a67f5a97","bin/log.lua":"8a553607f81b45e3e0e6d3087735c75fbb38e585d7d1f7a9451b3cb5d0dac330","bin/lyr.lua":"5b17b8cf560ac5dbe4f458d36dff853f51103492952048f233fcad8b319c04e6","bin/maxim.lua":"a68abcb1afae04c9e2177459cd6cb35cf417e4dc80a5bc4580e7cd9b05a44602","bin/norris.lua":"e3105b98d6ac2ba038847fe4a8977db6fbf513b5de6ca3052e7ce20f79d4a314","bin/potatoflight.lua":"2fbb0b6f8d78728d8cb0ec64af1bc598bd00cb55f202378e7acdb86bba71efd1","bin/potatonet.lua":"d58e6aee25190e62a826cc9d195c4aa7e91ac43147d9a8bb8e86d139c7c5bde9","bin/potatoplex.lua":"4399d7cc33004fb21be5a0e2ab8405b8e454c004395844ce7ec42a19965fd415","bin/regset.lua":"423879f14de9efb8192ee718a1d5e129e21f50c50799651b2dcff65287808807","bin/relay.lua":"261ae6c220b83506e3326e8f2b091d246baae458ff0d2ee87512be2c4e35a75d","bin/tau.lua":"45626e749b8734bf466b89f769ec3e5544983a55086c6a165eaabdc0b010b6ac","bin/threat_update.lua":"8f186d04e0845e77a6b5049a8cd182b68f1a5f3c4eb4b3e14ad6a3563ac8dd1e","bin/tryhaskell.lua":"07810d85145da65a3e434154c79d5a9d72f2dcbe59c8d6829040fb925df878ec","bin/umount.lua":"63b2480d5a1e9e5112805e16935a549eb016560eb3400a13bc11c10fcd7fd895","bin/uninstall.lua":"12744da9213a7dba4e72c3dd0a2ac8b84c3a8315247ee4c9aa9af392dfa50b82","bin/upd.lua":"9ce75f3d428f99263392814596b4f782ea17e7f6096dad6038eac65c3fd68cd5","bin/very-uninstall.lua":"90ff8362f85e0acefff011241b0161499a3dc47fa4f2a4c21f6f0789ab9f19b5","bin/viewsource.lua":"02b4dcdb3cf064e7018117fc68a574b260e21561f1813951e4e1de8f0c9420a6","bin/wipe.lua":"2dbc079215c0c06fda182b8878f533631708d95d6148c65f24c606bc3786e2fb","bin/workspace.lua":"acc8bb6f08b243378b68ab5f611e9a6cc8216b0713343dc93ddaa9101f07ffc5","potatobios.lua":"fb1dca42861ac01df033e172c6a612321455d32b7dbe2d7dd3351ada4552a78f","signing-key.tbl":"b32af5229c23af3bc03d538e42751b26044e404a7b1af064ed89894efe421607","startup":"a1008f5e11a1c8ec015ac4da3b783b8fb32c08a78f9dfab2b986c44e29b476ea","stdlib.hvl":"a6fd2620068f47794a9bbeed77bee3fd4962f848e6dd7c75137b30cd5665272e","xlib/00_cbor.lua":"cb00cf146c439edc4caf3a6d0913f6454aa421a85b5b40d7b7f4de5cd7f16a80","xlib/01_skynet.lua":"9cb565d639a0acd7c763c3e7422482532cd0bda0cdfcc720089ab4a87e551339","xlib/02_heavlisp.lua":"82cdabd5286058c0ea4f27956f8c1144e198769c8b8ce9e91b26c930d711f710","xlib/03_lolcrypt.lua":"0ca423837248e405898c436fd7f39c1fff63ba1a1c5610f3e9fb36151a698ff5"},"sizes":{"LICENSES":4725,"autorun.lua":217680,"bin/5rot26.lua":1661,"bin/BSOD.lua":104,"bin/b.lua":34,"bin/build.lua":639,"bin/ccemux.lua":1673,"bin/chronometer.lua":1152,"bin/chuck.lua":29,"bin/clear_space.lua":105,"bin/ctime.lua":1255,"bin/devfs.lua":3407,"bin/est.lua":787,"bin/exorcise.lua":208,"bin/factor.lua":4244,"bin/fortune.lua":24,"bin/game_mode.lua":226,"bin/grep.lua":1196,"bin/hacker.lua":8021,"bin/id.lua":548,"bin/init-screens.lua":36,"bin/intelligence.lua":309,"bin/kristminer.lua":5566,"bin/livegps.lua":980,"bin/lmatrix.lua":1005,"bin/loading.lua":7707,"bin/log.lua":379,"bin/lyr.lua":72,"bin/maxim.lua":22,"bin/norris.lua":45,"bin/potatoflight.lua":3417,"bin/potatonet.lua":19,"bin/potatoplex.lua":6584,"bin/regset.lua":314,"bin/relay.lua":3075,"bin/tau.lua":124,"bin/threat_update.lua":1353,"bin/tryhaskell.lua":1867,"bin/umount.lua":33,"bin/uninstall.lua":166,"bin/upd.lua":16,"bin/very-uninstall.lua":80,"bin/viewsource.lua":1275,"bin/wipe.lua":73,"bin/workspace.lua":42971,"potatobios.lua":69364,"signing-key.tbl":190,"startup":13489,"stdlib.hvl":851,"xlib/00_cbor.lua":15281,"xlib/01_skynet.lua":3286,"xlib/02_heavlisp.lua":15643,"xlib/03_lolcrypt.lua":3206},"timestamp":1725367584} -{"hash":"7afcc9c8baf9a13363a2f1de7636f155c96a6443f7a159c7a060db84fac6781c"} \ No newline at end of file +{"build":848,"description":"devfs changes","files":{"LICENSES":"f3549d84d66eb53dd4a421a4341d77d3d217c1b117d67e3be8f5211adcda0952","autorun.lua":"831f1a185f32a966668027483de157d955a661115fa692e6b71476ff6f7d3c81","bin/5rot26.lua":"417891a232e325476f980d31d88edc486d526611a6350ce47fd29cca464ebf2c","bin/BSOD.lua":"a2ea9bf1e64dbc2c314e3be71f46e973c0bc2b9c482395120f5d152c6d231e86","bin/b.lua":"5123c6d1bb2b3d6c8e7b4d1b94e60d47c3b6c64c5a0fe8bda8481b718ba00602","bin/build.lua":"a990239e1db05176dd0ba56bc0179eecccd8473d88c6c618d16e72ede270e4c2","bin/ccemux.lua":"239476f58835b86bbcac31ce8af3c3acd3d198a55ab9ada78c62fbf358625a98","bin/chronometer.lua":"db5363993a04382145aef7db2fbe262f0bf10697a589e1e2d2f9ce0f87430dd8","bin/chuck.lua":"571a1eacde435bbd9f54b493149339ac48972a3a4550635b9107da0091fe888a","bin/clear_space.lua":"fc3d52563adaf0491b71227f8b6f615d604063a89830a2ab86a20d10e1a07e97","bin/ctime.lua":"c64022ef0ac641ea531567d770adb306d0d632ff7bd2b692f4915021ed6787c0","bin/devfs.lua":"66e57c37c88bb3d718ec417fd5148be04e5ca464f36754060401c558cbd56486","bin/est.lua":"88ab488c2ded31d67816da8c309a63ac455b461368b3b943aeeb5106b1051cc0","bin/exorcise.lua":"ae25e5939ce52620b0a1e64679a1ac47bcaaff9e323d29c6651bce24a3e58116","bin/factor.lua":"39c2f1709a4258d754278860177c7bb2ea336a8b8392a4c3017c849705e63926","bin/fortune.lua":"64a595afb9ffbaa39622b32379d8dc40d4f1fd36d38027382ed0ae130ad0c59d","bin/game_mode.lua":"f1519969a83e6c7c001d4092cbc7806ea489652ea19022425a893fb4d153572f","bin/grep.lua":"1509bc267867b933e528ab74cfbc2a15fa2df0ec7389df4f9033194ab9037865","bin/hacker.lua":"889e1a47c5ff7470ddf61d87eb7cca9750193976139d513fbe67b7625195d65a","bin/id.lua":"82131679ee35c705458660ac31ab4f5f90169b43f2377fe420a99b1d4c03a4dd","bin/init-screens.lua":"c586a7704030dc1917262f04350e094e1e0ab084793eb1643222498f6436b597","bin/intelligence.lua":"0f14f5a5fb2c6053c19c7a8fa0ba335a69a6fb3b49941c3234dac59795cd3850","bin/kristminer.lua":"7e7f9fe2a6493d584ad6926cda915e02c1c3d800dc209680898ce930d0bb0e6f","bin/livegps.lua":"c3d17d495cda01aa1261e4c4fcd43439b29af422671972117ec34f68e32c5bba","bin/lmatrix.lua":"9d5728b93069d2b763bb8e1dd2a5542995c47daca61f385644431bfc315bc2c4","bin/loading.lua":"c85f7aa1765170325155b921c1fceeb62643f552f12d41b529a22af3a67f5a97","bin/log.lua":"8a553607f81b45e3e0e6d3087735c75fbb38e585d7d1f7a9451b3cb5d0dac330","bin/lyr.lua":"5b17b8cf560ac5dbe4f458d36dff853f51103492952048f233fcad8b319c04e6","bin/maxim.lua":"a68abcb1afae04c9e2177459cd6cb35cf417e4dc80a5bc4580e7cd9b05a44602","bin/norris.lua":"e3105b98d6ac2ba038847fe4a8977db6fbf513b5de6ca3052e7ce20f79d4a314","bin/potatoflight.lua":"2fbb0b6f8d78728d8cb0ec64af1bc598bd00cb55f202378e7acdb86bba71efd1","bin/potatonet.lua":"d58e6aee25190e62a826cc9d195c4aa7e91ac43147d9a8bb8e86d139c7c5bde9","bin/potatoplex.lua":"4399d7cc33004fb21be5a0e2ab8405b8e454c004395844ce7ec42a19965fd415","bin/regset.lua":"423879f14de9efb8192ee718a1d5e129e21f50c50799651b2dcff65287808807","bin/relay.lua":"261ae6c220b83506e3326e8f2b091d246baae458ff0d2ee87512be2c4e35a75d","bin/tau.lua":"45626e749b8734bf466b89f769ec3e5544983a55086c6a165eaabdc0b010b6ac","bin/threat_update.lua":"8f186d04e0845e77a6b5049a8cd182b68f1a5f3c4eb4b3e14ad6a3563ac8dd1e","bin/tryhaskell.lua":"07810d85145da65a3e434154c79d5a9d72f2dcbe59c8d6829040fb925df878ec","bin/umount.lua":"63b2480d5a1e9e5112805e16935a549eb016560eb3400a13bc11c10fcd7fd895","bin/uninstall.lua":"12744da9213a7dba4e72c3dd0a2ac8b84c3a8315247ee4c9aa9af392dfa50b82","bin/upd.lua":"9ce75f3d428f99263392814596b4f782ea17e7f6096dad6038eac65c3fd68cd5","bin/very-uninstall.lua":"90ff8362f85e0acefff011241b0161499a3dc47fa4f2a4c21f6f0789ab9f19b5","bin/viewsource.lua":"02b4dcdb3cf064e7018117fc68a574b260e21561f1813951e4e1de8f0c9420a6","bin/wipe.lua":"2dbc079215c0c06fda182b8878f533631708d95d6148c65f24c606bc3786e2fb","bin/workspace.lua":"acc8bb6f08b243378b68ab5f611e9a6cc8216b0713343dc93ddaa9101f07ffc5","potatobios.lua":"4df202147d3c5b0c04ca11debe30b8cd71b26bfe2712799bc98c9c000b3c910f","signing-key.tbl":"b32af5229c23af3bc03d538e42751b26044e404a7b1af064ed89894efe421607","startup":"a1008f5e11a1c8ec015ac4da3b783b8fb32c08a78f9dfab2b986c44e29b476ea","stdlib.hvl":"a6fd2620068f47794a9bbeed77bee3fd4962f848e6dd7c75137b30cd5665272e","update-key.hex":"8d8afb7a45833bb7d68f929421ad60a211d4d73e0ee03b24dc0106ba1de2e1a0","xlib/00_cbor.lua":"cb00cf146c439edc4caf3a6d0913f6454aa421a85b5b40d7b7f4de5cd7f16a80","xlib/01_skynet.lua":"9cb565d639a0acd7c763c3e7422482532cd0bda0cdfcc720089ab4a87e551339","xlib/02_heavlisp.lua":"82cdabd5286058c0ea4f27956f8c1144e198769c8b8ce9e91b26c930d711f710","xlib/03_lolcrypt.lua":"0ca423837248e405898c436fd7f39c1fff63ba1a1c5610f3e9fb36151a698ff5"},"sizes":{"LICENSES":4725,"autorun.lua":111929,"bin/5rot26.lua":1661,"bin/BSOD.lua":104,"bin/b.lua":34,"bin/build.lua":639,"bin/ccemux.lua":1673,"bin/chronometer.lua":1152,"bin/chuck.lua":29,"bin/clear_space.lua":105,"bin/ctime.lua":1255,"bin/devfs.lua":3826,"bin/est.lua":787,"bin/exorcise.lua":208,"bin/factor.lua":4244,"bin/fortune.lua":24,"bin/game_mode.lua":226,"bin/grep.lua":1196,"bin/hacker.lua":8021,"bin/id.lua":548,"bin/init-screens.lua":36,"bin/intelligence.lua":309,"bin/kristminer.lua":5566,"bin/livegps.lua":980,"bin/lmatrix.lua":1005,"bin/loading.lua":7707,"bin/log.lua":379,"bin/lyr.lua":72,"bin/maxim.lua":22,"bin/norris.lua":45,"bin/potatoflight.lua":3417,"bin/potatonet.lua":19,"bin/potatoplex.lua":6584,"bin/regset.lua":314,"bin/relay.lua":3075,"bin/tau.lua":124,"bin/threat_update.lua":1353,"bin/tryhaskell.lua":1867,"bin/umount.lua":33,"bin/uninstall.lua":166,"bin/upd.lua":16,"bin/very-uninstall.lua":80,"bin/viewsource.lua":1275,"bin/wipe.lua":73,"bin/workspace.lua":42971,"potatobios.lua":43072,"signing-key.tbl":190,"startup":13489,"stdlib.hvl":851,"update-key.hex":44,"xlib/00_cbor.lua":15281,"xlib/01_skynet.lua":3286,"xlib/02_heavlisp.lua":15643,"xlib/03_lolcrypt.lua":3206},"timestamp":1741614827} +{"hash":"fdfacd71ab5ae38c1d882ad0f9624c2a84fd430e1e7c7e1f4f0e94ec3d9d4fd7","sig":"427821bfbde8f1af96eb9f637ec9554adddb780037b22020bca43024c8b5d62272ab9166ab91673cd10e"} \ No newline at end of file diff --git a/src/bin/devfs.lua b/src/bin/devfs.lua index a312f97..86ed9ac 100644 --- a/src/bin/devfs.lua +++ b/src/bin/devfs.lua @@ -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) \ No newline at end of file +fs.mountVFS(shell.resolve(...), vfs) diff --git a/src/main.lua b/src/main.lua index b7b0e8b..c8d3bff 100644 --- a/src/main.lua +++ b/src/main.lua @@ -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"