1
0
mirror of https://github.com/kepler155c/opus synced 2024-12-28 17:40:26 +00:00

fix netfs issues - implement fs.attributes

This commit is contained in:
kepler155c@gmail.com 2020-04-27 15:44:09 -06:00
parent d72ae3de4a
commit e116caf16e
8 changed files with 78 additions and 52 deletions

View File

@ -10,10 +10,8 @@ local os = _G.os
local textutils = _G.textutils
local term = _G.term
local _exit
local sandboxEnv = setmetatable(Util.shallowCopy(_ENV), { __index = _G })
sandboxEnv.exit = function() _exit = true end
sandboxEnv.exit = function() UI:quit() end
sandboxEnv._echo = function( ... ) return { ... } end
_G.requireInjector(sandboxEnv)
@ -363,10 +361,6 @@ function page:executeStatement(statement)
self:emit({ type = 'show_output' })
end
end
if _exit then
UI:quit()
end
end
local args = Util.parse(...)

View File

@ -151,7 +151,7 @@ if action == 'uninstall' then
runScript(manifest.uninstall)
local packageDir = fs.combine('packages', name)
fs.delete(packageDir)
fs.delete(fs.resolve(packageDir))
print('removed: ' .. packageDir)
return
end

View File

@ -19,6 +19,10 @@ for k,fn in pairs(fs) do
end
end
function nativefs.resolve(_, dir)
return dir
end
function nativefs.list(node, dir)
local files
if fs.native.isDir(dir) then
@ -137,7 +141,7 @@ end
fs.getNode = getNode
local methods = { 'delete', 'getFreeSpace', 'exists', 'isDir', 'getSize',
'isReadOnly', 'makeDir', 'getDrive', 'list', 'open' }
'isReadOnly', 'makeDir', 'getDrive', 'list', 'open', 'attributes' }
for _,m in pairs(methods) do
fs[m] = function(dir, ...)
@ -147,6 +151,12 @@ for _,m in pairs(methods) do
end
end
-- if a link, return the source for this link
function fs.resolve(dir)
local n = getNode(dir)
return n.fs.resolve and n.fs.resolve(n, dir) or dir
end
function fs.complete(partial, dir, includeFiles, includeSlash)
dir = fs.combine(dir, '')
local node = getNode(dir)
@ -268,14 +278,11 @@ function fs.mount(path, fstype, ...)
error('Invalid file system type')
end
-- hack - get the mount point for the path
-- ie. if packages is mapped to disk/packages
-- and a request to mount /packages/foo
-- then use disk/packages/foo as the mountPoint
local n = getNode(path)
if n.fstype == 'linkfs' then
path = path:gsub(n.mountPoint, n.source, 1)
end
-- get the mount point for the path
-- ie. if packages is mapped to disk/packages
-- and a request to mount /packages/foo
-- then use disk/packages/foo as the mountPoint
path = fs.resolve(path)
local node = vfs.mount(path, ...)
if node then
@ -290,8 +297,7 @@ end
if not tp.nodes[d] then
tp.nodes[d] = Util.shallowCopy(tp)
-- another related hack
if tp.fstype == 'linkfs' then
if tp.nodes[d].source then
tp.nodes[d].source = fs.combine(tp.nodes[d].source, d)
end

View File

@ -4,16 +4,20 @@ local linkfs = { }
-- TODO: implement broken links
local methods = { 'exists', 'getFreeSpace', 'getSize',
local methods = { 'exists', 'getFreeSpace', 'getSize', 'attributes',
'isDir', 'isReadOnly', 'list', 'listEx', 'makeDir', 'open', 'getDrive' }
for _,m in pairs(methods) do
linkfs[m] = function(node, dir, ...)
dir = dir:gsub(node.mountPoint, node.source, 1)
dir = linkfs.resolve(node, dir)
return fs[m](dir, ...)
end
end
function linkfs.resolve(node, dir)
return dir:gsub(node.mountPoint, node.source, 1)
end
function linkfs.mount(_, source)
if not source then
error('Source is required')

View File

@ -6,7 +6,6 @@ local fs = _G.fs
local netfs = { }
local function remoteCommand(node, msg)
for _ = 1, 2 do
if not node.socket then
node.socket = Socket.connect(node.id, 139)
@ -33,17 +32,17 @@ local function remoteCommand(node, msg)
error('netfs: Connection failed', 2)
end
local methods = { 'delete', 'exists', 'getFreeSpace', 'makeDir', 'list', 'listEx' }
local methods = { 'delete', 'exists', 'getFreeSpace', 'makeDir', 'list', 'listEx', 'attributes' }
local function resolveDir(dir, node)
local function resolve(node, dir)
-- TODO: Wrong ! (does not support names with dashes)
dir = dir:gsub(node.mountPoint, '', 1)
return fs.combine(node.directory, dir)
return fs.combine(node.source, dir)
end
for _,m in pairs(methods) do
netfs[m] = function(node, dir)
dir = resolveDir(dir, node)
dir = resolve(node, dir)
return remoteCommand(node, {
fn = m,
@ -52,14 +51,14 @@ for _,m in pairs(methods) do
end
end
function netfs.mount(_, id, directory)
function netfs.mount(_, id, source)
if not id or not tonumber(id) then
error('ramfs syntax: computerId [directory]')
end
return {
id = tonumber(id),
nodes = { },
directory = directory or '',
source = source or '',
}
end
@ -68,7 +67,7 @@ function netfs.getDrive()
end
function netfs.complete(node, partial, dir, includeFiles, includeSlash)
dir = resolveDir(dir, node)
dir = resolve(node, dir)
return remoteCommand(node, {
fn = 'complete',
@ -77,8 +76,8 @@ function netfs.complete(node, partial, dir, includeFiles, includeSlash)
end
function netfs.copy(node, s, t)
s = resolveDir(s, node)
t = resolveDir(t, node)
s = resolve(node, s)
t = resolve(node, t)
return remoteCommand(node, {
fn = 'copy',
@ -87,37 +86,37 @@ function netfs.copy(node, s, t)
end
function netfs.isDir(node, dir)
if dir == node.mountPoint and node.directory == '' then
if dir == node.mountPoint and node.source == '' then
return true
end
return remoteCommand(node, {
fn = 'isDir',
args = { resolveDir(dir, node) },
args = { resolve(node, dir) },
})
end
function netfs.isReadOnly(node, dir)
if dir == node.mountPoint and node.directory == '' then
if dir == node.mountPoint and node.source == '' then
return false
end
return remoteCommand(node, {
fn = 'isReadOnly',
args = { resolveDir(dir, node) },
args = { resolve(node, dir) },
})
end
function netfs.getSize(node, dir)
if dir == node.mountPoint and node.directory == '' then
if dir == node.mountPoint and node.source == '' then
return 0
end
return remoteCommand(node, {
fn = 'getSize',
args = { resolveDir(dir, node) },
args = { resolve(node, dir) },
})
end
function netfs.find(node, spec)
spec = resolveDir(spec, node)
spec = resolve(node, spec)
local list = remoteCommand(node, {
fn = 'find',
args = { spec },
@ -131,8 +130,8 @@ function netfs.find(node, spec)
end
function netfs.move(node, s, t)
s = resolveDir(s, node)
t = resolveDir(t, node)
s = resolve(node, s)
t = resolve(node, t)
return remoteCommand(node, {
fn = 'move',
@ -141,7 +140,7 @@ function netfs.move(node, s, t)
end
function netfs.open(node, fn, fl)
fn = resolveDir(fn, node)
fn = resolve(node, fn)
local vfh = remoteCommand(node, {
fn = 'open',

View File

@ -9,15 +9,28 @@ function ramfs.mount(_, nodeType)
return {
nodes = { },
size = 0,
created = os.epoch('utc'),
modification = os.epoch('utc'),
}
elseif nodeType == 'file' then
return {
size = 0,
created = os.epoch('utc'),
modification = os.epoch('utc'),
}
end
error('ramfs syntax: [directory, file]')
end
function ramfs.attributes(node)
return {
created = node.created,
isDir = not not node.nodes,
modification = node.modification,
size = node.size,
}
end
function ramfs.delete(node, dir)
if node.mountPoint == dir then
fs.unmount(node.mountPoint)

View File

@ -11,6 +11,17 @@ function urlfs.mount(_, url)
end
return {
url = url,
created = os.epoch('utc'),
modification = os.epoch('utc'),
}
end
function urlfs.attributes(node)
return {
created = node.created,
isDir = false,
modification = node.modification,
size = node.size or 0,
}
end

View File

@ -6,12 +6,11 @@ local Util = require('opus.util')
local device = _G.device
local os = _G.os
local network = _G.network
local socketClass = { }
function socketClass:read(timeout)
local data, distance = network.getTransport().read(self)
local data, distance = _G.network.getTransport().read(self)
if data then
return data, distance
end
@ -26,7 +25,7 @@ function socketClass:read(timeout)
local e, id = os.pullEvent()
if e == 'transport_' .. self.uid then
data, distance = network.getTransport().read(self)
data, distance = _G.network.getTransport().read(self)
if data then
os.cancelTimer(timerId)
return data, distance
@ -47,7 +46,7 @@ end
function socketClass:write(data)
if self.connected then
network.getTransport().write(self, {
_G.network.getTransport().write(self, {
type = 'DATA',
seq = self.wseq,
data = data,
@ -58,7 +57,7 @@ end
function socketClass:ping()
if self.connected then
network.getTransport().ping(self)
_G.network.getTransport().ping(self)
return true
end
end
@ -72,7 +71,7 @@ function socketClass:close()
self.connected = false
end
device.wireless_modem.close(self.sport)
network.getTransport().close(self)
_G.network.getTransport().close(self)
end
local Socket = { }
@ -127,9 +126,9 @@ function Socket.connect(host, port, options)
local socket = newSocket(host == os.getComputerID())
socket.dhost = tonumber(host)
if options and options.keypair then
socket.privKey, socket.pubKey = unpack(options.keypair)
socket.privKey, socket.pubKey = table.unpack(options.keypair)
else
socket.privKey, socket.pubKey = network.getKeyPair()
socket.privKey, socket.pubKey = _G.network.getKeyPair()
end
local identifier = options and options.identifier or Security.getIdentifier()
@ -159,7 +158,7 @@ function Socket.connect(host, port, options)
socket.remotePubKey = Util.hexToByteArray(msg.pk)
socket.options = msg.options or { }
setupCrypto(socket, true)
network.getTransport().open(socket)
_G.network.getTransport().open(socket)
return socket
elseif msg.type == 'NOPASS' then
@ -192,7 +191,7 @@ local function trusted(socket, msg, options)
if data and data.ts and tonumber(data.ts) then
if math.abs(os.epoch('utc') - data.ts) < 4096 then
socket.remotePubKey = Util.hexToByteArray(data.pk)
socket.privKey, socket.pubKey = network.getKeyPair()
socket.privKey, socket.pubKey = _G.network.getKeyPair()
setupCrypto(socket)
return true
end
@ -241,7 +240,7 @@ function Socket.server(port, options)
options = socket.options.ENCRYPT and { ENCRYPT = true },
})
network.getTransport().open(socket)
_G.network.getTransport().open(socket)
return socket
else