fix drive mounts, VFS listings(ish)
This commit is contained in:
parent
288ef5f03a
commit
2453c7756a
@ -220,12 +220,16 @@ local function create_FS(vfstree)
|
|||||||
return last_usable_node, last_segs
|
return last_usable_node, last_segs
|
||||||
end
|
end
|
||||||
|
|
||||||
local function resolve_path(sandbox_path)
|
local function resolve_node_segs(node, segs)
|
||||||
local node, segs = resolve(sandbox_path)
|
|
||||||
if node.mount then return fs, fscombine(node.mount, combine(segs)) end
|
if node.mount then return fs, fscombine(node.mount, combine(segs)) end
|
||||||
return node.vfs, combine(segs)
|
return node.vfs, combine(segs)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function resolve_path(sandbox_path)
|
||||||
|
local node, segs = resolve(sandbox_path)
|
||||||
|
return resolve_node_segs(node, segs)
|
||||||
|
end
|
||||||
|
|
||||||
local function lift_to_sandbox(f, n)
|
local function lift_to_sandbox(f, n)
|
||||||
return function(path)
|
return function(path)
|
||||||
local vfs, path = resolve_path(path)
|
local vfs, path = resolve_path(path)
|
||||||
@ -298,7 +302,25 @@ local function create_FS(vfstree)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
add_to_table(new, map(lift_to_sandbox, copy_some_keys {"isDir", "getDrive", "getSize", "getFreeSpace", "makeDir", "delete", "isDriveRoot", "exists", "isReadOnly", "list", "attributes"} (fs)))
|
function new.list(path)
|
||||||
|
local node, segs = resolve(path)
|
||||||
|
local vfs, path = resolve_node_segs(node, segs)
|
||||||
|
if #segs > 0 then return vfs.list(path) end
|
||||||
|
local out = {}
|
||||||
|
local seen = {}
|
||||||
|
for k, v in pairs(node.children or {}) do
|
||||||
|
table.insert(out, k)
|
||||||
|
seen[k] = true
|
||||||
|
end
|
||||||
|
for _, v in pairs(vfs.list(path)) do
|
||||||
|
if not seen[v] then
|
||||||
|
table.insert(out, v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return out
|
||||||
|
end
|
||||||
|
|
||||||
|
add_to_table(new, map(lift_to_sandbox, copy_some_keys {"isDir", "getDrive", "getSize", "getFreeSpace", "makeDir", "delete", "isDriveRoot", "exists", "isReadOnly", "attributes"} (fs)))
|
||||||
|
|
||||||
function new.find(wildcard)
|
function new.find(wildcard)
|
||||||
local function recurse_spec(results, path, spec) -- From here: https://github.com/Sorroko/cclite/blob/62677542ed63bd4db212f83da1357cb953e82ce3/src/emulator/native_api.lua
|
local function recurse_spec(results, path, spec) -- From here: https://github.com/Sorroko/cclite/blob/62677542ed63bd4db212f83da1357cb953e82ce3/src/emulator/native_api.lua
|
||||||
|
53
src/main.lua
53
src/main.lua
@ -1299,6 +1299,31 @@ local function run_with_sandbox()
|
|||||||
|
|
||||||
local yafss = require "yafss"
|
local yafss = require "yafss"
|
||||||
|
|
||||||
|
local drive_mounts = {
|
||||||
|
children = {},
|
||||||
|
vfs = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
function drive_mounts.vfs.list(path)
|
||||||
|
local out = {}
|
||||||
|
for k, v in pairs(drive_mounts.children) do
|
||||||
|
table.insert(out, k)
|
||||||
|
end
|
||||||
|
return out
|
||||||
|
end
|
||||||
|
|
||||||
|
function drive_mounts.vfs.exists(path)
|
||||||
|
return drive_mounts.children[path] ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function drive_mounts.vfs.isDir(path) return true end
|
||||||
|
function drive_mounts.vfs.getDrive(path) return "disks" end
|
||||||
|
function drive_mounts.vfs.getSize(path) return 0 end
|
||||||
|
function drive_mounts.vfs.getFreeSpace(path) return 0 end
|
||||||
|
function drive_mounts.vfs.makeDir(path) end
|
||||||
|
function drive_mounts.vfs.delete(path) end
|
||||||
|
function drive_mounts.vfs.isReadOnly(path) return true end
|
||||||
|
|
||||||
local vfstree = {
|
local vfstree = {
|
||||||
mount = "potatOS",
|
mount = "potatOS",
|
||||||
children = {
|
children = {
|
||||||
@ -1322,7 +1347,8 @@ local function run_with_sandbox()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
["disks"] = drive_mounts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1362,6 +1388,18 @@ local function run_with_sandbox()
|
|||||||
local computers = {}
|
local computers = {}
|
||||||
local compcount = 0
|
local compcount = 0
|
||||||
local signs = {}
|
local signs = {}
|
||||||
|
|
||||||
|
local function mount_disk(drive_name)
|
||||||
|
local mountpoint = peripheral.call(drive_name, "getMountPath")
|
||||||
|
if mountpoint then
|
||||||
|
drive_mounts.children[drive_name] = { mount = mountpoint }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function unmount_disk(drive_name)
|
||||||
|
drive_mounts.children[drive_name] = nil
|
||||||
|
end
|
||||||
|
|
||||||
local function add_peripheral(name)
|
local function add_peripheral(name)
|
||||||
local typ = peripheral.getType(name)
|
local typ = peripheral.getType(name)
|
||||||
if typ == "modem" then
|
if typ == "modem" then
|
||||||
@ -1371,10 +1409,16 @@ local function run_with_sandbox()
|
|||||||
compcount = compcount + 1
|
compcount = compcount + 1
|
||||||
elseif typ == "minecraft:sign" then
|
elseif typ == "minecraft:sign" then
|
||||||
signs[name] = true
|
signs[name] = true
|
||||||
|
elseif typ == "drive" then
|
||||||
|
if peripheral.call(name, "isDiskPresent") then
|
||||||
|
mount_disk(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
for _, name in pairs(peripheral.getNames()) do add_peripheral(name) end
|
for _, name in pairs(peripheral.getNames()) do add_peripheral(name) end
|
||||||
local timer = os.startTimer(1)
|
local timer = os.startTimer(1)
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
local e, name, channel, _, message = os.pullEvent()
|
local e, name, channel, _, message = os.pullEvent()
|
||||||
if e == "peripheral" then add_peripheral(name)
|
if e == "peripheral" then add_peripheral(name)
|
||||||
@ -1382,7 +1426,8 @@ local function run_with_sandbox()
|
|||||||
local typ = peripheral.getType(name)
|
local typ = peripheral.getType(name)
|
||||||
if typ == "computer" then computers[name] = nil compcount = compcount - 1
|
if typ == "computer" then computers[name] = nil compcount = compcount - 1
|
||||||
elseif typ == "modem" then modems[name] = nil
|
elseif typ == "modem" then modems[name] = nil
|
||||||
elseif typ == "minecraft:sign" then signs[name] = nil end
|
elseif typ == "minecraft:sign" then signs[name] = nil
|
||||||
|
elseif typ == "drive" then unmount_disk(name) end
|
||||||
elseif e == "modem_message" then
|
elseif e == "modem_message" then
|
||||||
if channel == 62381 and type(message) == "string" then
|
if channel == 62381 and type(message) == "string" then
|
||||||
add_log("netd message %s", message)
|
add_log("netd message %s", message)
|
||||||
@ -1403,6 +1448,10 @@ local function run_with_sandbox()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
timer = os.startTimer(1 + math.random(0, compcount * 2))
|
timer = os.startTimer(1 + math.random(0, compcount * 2))
|
||||||
|
elseif e == "disk" then
|
||||||
|
mount_disk(name)
|
||||||
|
elseif e == "disk_eject" then
|
||||||
|
unmount_disk(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end, "netd", { grants = { [notermsentinel] = true }, restrictions = {} })
|
end, "netd", { grants = { [notermsentinel] = true }, restrictions = {} })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user