Files
MDB/main.lua

55 lines
1.3 KiB
Lua
Raw Normal View History

-- http://justus.l--n.de:3000/JUFS/MDB/raw/branch/main/main.lua
-- or use bootstrapper
print("Copyright JUFS Technologies aka. Justus Wolff 2026")
print("MDB - Multi disk Data Base")
print("init API")
local API = {}
function API.getDisks()
local disks = {peripheral.find("drive")}
local out = {}
for _,v in pairs(disks) do
if v.isDiskPresent() and v.hasData() then table.insert(out, v.getMountPath()) end
end
return out
end
2026-03-13 14:04:07 +01:00
function API._buildCandidateTree(...)
local path = {...}
local candidates = {}
for _,v in pairs(API.getDisks()) do
2026-03-11 18:14:51 +01:00
for _,newcan in pairs(fs.list(v)) do
table.insert(candidates, fs.combine(v, newcan))
end
end
for _,v in pairs(path) do
local temp = {}
for _,cc in pairs(candidates) do
if fs.getName(cc) == v then
table.insert(temp, cc)
end
end
candidates = temp
end
return candidates
end
function API.list(...)
2026-03-13 14:04:07 +01:00
local final = {}
for _,v in pairs(API._buildCandidateTree(...)) do
2026-03-16 20:34:18 +01:00
table.insert(final, fs.getName(v))
2026-03-13 14:04:07 +01:00
end
return final
end
print("Disks: ")
local disks = API.getDisks()
for _,v in pairs(disks) do
2026-03-11 18:14:51 +01:00
print(" "..v..": "..tostring(fs.getFreeSpace("/")).."/"..tostring(fs.getCapacity("/")))
end
for _,v in pairs(API.list()) do
print(v)
end
return API