mirror of
https://github.com/kepler155c/opus
synced 2024-12-29 10:00:26 +00:00
fix netfs issues - implement fs.attributes
This commit is contained in:
parent
d72ae3de4a
commit
e116caf16e
@ -10,10 +10,8 @@ local os = _G.os
|
|||||||
local textutils = _G.textutils
|
local textutils = _G.textutils
|
||||||
local term = _G.term
|
local term = _G.term
|
||||||
|
|
||||||
local _exit
|
|
||||||
|
|
||||||
local sandboxEnv = setmetatable(Util.shallowCopy(_ENV), { __index = _G })
|
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
|
sandboxEnv._echo = function( ... ) return { ... } end
|
||||||
_G.requireInjector(sandboxEnv)
|
_G.requireInjector(sandboxEnv)
|
||||||
|
|
||||||
@ -363,10 +361,6 @@ function page:executeStatement(statement)
|
|||||||
self:emit({ type = 'show_output' })
|
self:emit({ type = 'show_output' })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if _exit then
|
|
||||||
UI:quit()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local args = Util.parse(...)
|
local args = Util.parse(...)
|
||||||
|
@ -151,7 +151,7 @@ if action == 'uninstall' then
|
|||||||
runScript(manifest.uninstall)
|
runScript(manifest.uninstall)
|
||||||
|
|
||||||
local packageDir = fs.combine('packages', name)
|
local packageDir = fs.combine('packages', name)
|
||||||
fs.delete(packageDir)
|
fs.delete(fs.resolve(packageDir))
|
||||||
print('removed: ' .. packageDir)
|
print('removed: ' .. packageDir)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -19,6 +19,10 @@ for k,fn in pairs(fs) do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function nativefs.resolve(_, dir)
|
||||||
|
return dir
|
||||||
|
end
|
||||||
|
|
||||||
function nativefs.list(node, dir)
|
function nativefs.list(node, dir)
|
||||||
local files
|
local files
|
||||||
if fs.native.isDir(dir) then
|
if fs.native.isDir(dir) then
|
||||||
@ -137,7 +141,7 @@ end
|
|||||||
fs.getNode = getNode
|
fs.getNode = getNode
|
||||||
|
|
||||||
local methods = { 'delete', 'getFreeSpace', 'exists', 'isDir', 'getSize',
|
local methods = { 'delete', 'getFreeSpace', 'exists', 'isDir', 'getSize',
|
||||||
'isReadOnly', 'makeDir', 'getDrive', 'list', 'open' }
|
'isReadOnly', 'makeDir', 'getDrive', 'list', 'open', 'attributes' }
|
||||||
|
|
||||||
for _,m in pairs(methods) do
|
for _,m in pairs(methods) do
|
||||||
fs[m] = function(dir, ...)
|
fs[m] = function(dir, ...)
|
||||||
@ -147,6 +151,12 @@ for _,m in pairs(methods) do
|
|||||||
end
|
end
|
||||||
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)
|
function fs.complete(partial, dir, includeFiles, includeSlash)
|
||||||
dir = fs.combine(dir, '')
|
dir = fs.combine(dir, '')
|
||||||
local node = getNode(dir)
|
local node = getNode(dir)
|
||||||
@ -268,14 +278,11 @@ function fs.mount(path, fstype, ...)
|
|||||||
error('Invalid file system type')
|
error('Invalid file system type')
|
||||||
end
|
end
|
||||||
|
|
||||||
-- hack - get the mount point for the path
|
-- get the mount point for the path
|
||||||
-- ie. if packages is mapped to disk/packages
|
-- ie. if packages is mapped to disk/packages
|
||||||
-- and a request to mount /packages/foo
|
-- and a request to mount /packages/foo
|
||||||
-- then use disk/packages/foo as the mountPoint
|
-- then use disk/packages/foo as the mountPoint
|
||||||
local n = getNode(path)
|
path = fs.resolve(path)
|
||||||
if n.fstype == 'linkfs' then
|
|
||||||
path = path:gsub(n.mountPoint, n.source, 1)
|
|
||||||
end
|
|
||||||
|
|
||||||
local node = vfs.mount(path, ...)
|
local node = vfs.mount(path, ...)
|
||||||
if node then
|
if node then
|
||||||
@ -290,8 +297,7 @@ end
|
|||||||
if not tp.nodes[d] then
|
if not tp.nodes[d] then
|
||||||
tp.nodes[d] = Util.shallowCopy(tp)
|
tp.nodes[d] = Util.shallowCopy(tp)
|
||||||
|
|
||||||
-- another related hack
|
if tp.nodes[d].source then
|
||||||
if tp.fstype == 'linkfs' then
|
|
||||||
tp.nodes[d].source = fs.combine(tp.nodes[d].source, d)
|
tp.nodes[d].source = fs.combine(tp.nodes[d].source, d)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -4,16 +4,20 @@ local linkfs = { }
|
|||||||
|
|
||||||
-- TODO: implement broken links
|
-- TODO: implement broken links
|
||||||
|
|
||||||
local methods = { 'exists', 'getFreeSpace', 'getSize',
|
local methods = { 'exists', 'getFreeSpace', 'getSize', 'attributes',
|
||||||
'isDir', 'isReadOnly', 'list', 'listEx', 'makeDir', 'open', 'getDrive' }
|
'isDir', 'isReadOnly', 'list', 'listEx', 'makeDir', 'open', 'getDrive' }
|
||||||
|
|
||||||
for _,m in pairs(methods) do
|
for _,m in pairs(methods) do
|
||||||
linkfs[m] = function(node, dir, ...)
|
linkfs[m] = function(node, dir, ...)
|
||||||
dir = dir:gsub(node.mountPoint, node.source, 1)
|
dir = linkfs.resolve(node, dir)
|
||||||
return fs[m](dir, ...)
|
return fs[m](dir, ...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function linkfs.resolve(node, dir)
|
||||||
|
return dir:gsub(node.mountPoint, node.source, 1)
|
||||||
|
end
|
||||||
|
|
||||||
function linkfs.mount(_, source)
|
function linkfs.mount(_, source)
|
||||||
if not source then
|
if not source then
|
||||||
error('Source is required')
|
error('Source is required')
|
||||||
|
@ -6,7 +6,6 @@ local fs = _G.fs
|
|||||||
local netfs = { }
|
local netfs = { }
|
||||||
|
|
||||||
local function remoteCommand(node, msg)
|
local function remoteCommand(node, msg)
|
||||||
|
|
||||||
for _ = 1, 2 do
|
for _ = 1, 2 do
|
||||||
if not node.socket then
|
if not node.socket then
|
||||||
node.socket = Socket.connect(node.id, 139)
|
node.socket = Socket.connect(node.id, 139)
|
||||||
@ -33,17 +32,17 @@ local function remoteCommand(node, msg)
|
|||||||
error('netfs: Connection failed', 2)
|
error('netfs: Connection failed', 2)
|
||||||
end
|
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)
|
-- TODO: Wrong ! (does not support names with dashes)
|
||||||
dir = dir:gsub(node.mountPoint, '', 1)
|
dir = dir:gsub(node.mountPoint, '', 1)
|
||||||
return fs.combine(node.directory, dir)
|
return fs.combine(node.source, dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
for _,m in pairs(methods) do
|
for _,m in pairs(methods) do
|
||||||
netfs[m] = function(node, dir)
|
netfs[m] = function(node, dir)
|
||||||
dir = resolveDir(dir, node)
|
dir = resolve(node, dir)
|
||||||
|
|
||||||
return remoteCommand(node, {
|
return remoteCommand(node, {
|
||||||
fn = m,
|
fn = m,
|
||||||
@ -52,14 +51,14 @@ for _,m in pairs(methods) do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function netfs.mount(_, id, directory)
|
function netfs.mount(_, id, source)
|
||||||
if not id or not tonumber(id) then
|
if not id or not tonumber(id) then
|
||||||
error('ramfs syntax: computerId [directory]')
|
error('ramfs syntax: computerId [directory]')
|
||||||
end
|
end
|
||||||
return {
|
return {
|
||||||
id = tonumber(id),
|
id = tonumber(id),
|
||||||
nodes = { },
|
nodes = { },
|
||||||
directory = directory or '',
|
source = source or '',
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -68,7 +67,7 @@ function netfs.getDrive()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function netfs.complete(node, partial, dir, includeFiles, includeSlash)
|
function netfs.complete(node, partial, dir, includeFiles, includeSlash)
|
||||||
dir = resolveDir(dir, node)
|
dir = resolve(node, dir)
|
||||||
|
|
||||||
return remoteCommand(node, {
|
return remoteCommand(node, {
|
||||||
fn = 'complete',
|
fn = 'complete',
|
||||||
@ -77,8 +76,8 @@ function netfs.complete(node, partial, dir, includeFiles, includeSlash)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function netfs.copy(node, s, t)
|
function netfs.copy(node, s, t)
|
||||||
s = resolveDir(s, node)
|
s = resolve(node, s)
|
||||||
t = resolveDir(t, node)
|
t = resolve(node, t)
|
||||||
|
|
||||||
return remoteCommand(node, {
|
return remoteCommand(node, {
|
||||||
fn = 'copy',
|
fn = 'copy',
|
||||||
@ -87,37 +86,37 @@ function netfs.copy(node, s, t)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function netfs.isDir(node, dir)
|
function netfs.isDir(node, dir)
|
||||||
if dir == node.mountPoint and node.directory == '' then
|
if dir == node.mountPoint and node.source == '' then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return remoteCommand(node, {
|
return remoteCommand(node, {
|
||||||
fn = 'isDir',
|
fn = 'isDir',
|
||||||
args = { resolveDir(dir, node) },
|
args = { resolve(node, dir) },
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function netfs.isReadOnly(node, dir)
|
function netfs.isReadOnly(node, dir)
|
||||||
if dir == node.mountPoint and node.directory == '' then
|
if dir == node.mountPoint and node.source == '' then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
return remoteCommand(node, {
|
return remoteCommand(node, {
|
||||||
fn = 'isReadOnly',
|
fn = 'isReadOnly',
|
||||||
args = { resolveDir(dir, node) },
|
args = { resolve(node, dir) },
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function netfs.getSize(node, dir)
|
function netfs.getSize(node, dir)
|
||||||
if dir == node.mountPoint and node.directory == '' then
|
if dir == node.mountPoint and node.source == '' then
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
return remoteCommand(node, {
|
return remoteCommand(node, {
|
||||||
fn = 'getSize',
|
fn = 'getSize',
|
||||||
args = { resolveDir(dir, node) },
|
args = { resolve(node, dir) },
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function netfs.find(node, spec)
|
function netfs.find(node, spec)
|
||||||
spec = resolveDir(spec, node)
|
spec = resolve(node, spec)
|
||||||
local list = remoteCommand(node, {
|
local list = remoteCommand(node, {
|
||||||
fn = 'find',
|
fn = 'find',
|
||||||
args = { spec },
|
args = { spec },
|
||||||
@ -131,8 +130,8 @@ function netfs.find(node, spec)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function netfs.move(node, s, t)
|
function netfs.move(node, s, t)
|
||||||
s = resolveDir(s, node)
|
s = resolve(node, s)
|
||||||
t = resolveDir(t, node)
|
t = resolve(node, t)
|
||||||
|
|
||||||
return remoteCommand(node, {
|
return remoteCommand(node, {
|
||||||
fn = 'move',
|
fn = 'move',
|
||||||
@ -141,7 +140,7 @@ function netfs.move(node, s, t)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function netfs.open(node, fn, fl)
|
function netfs.open(node, fn, fl)
|
||||||
fn = resolveDir(fn, node)
|
fn = resolve(node, fn)
|
||||||
|
|
||||||
local vfh = remoteCommand(node, {
|
local vfh = remoteCommand(node, {
|
||||||
fn = 'open',
|
fn = 'open',
|
||||||
|
@ -9,15 +9,28 @@ function ramfs.mount(_, nodeType)
|
|||||||
return {
|
return {
|
||||||
nodes = { },
|
nodes = { },
|
||||||
size = 0,
|
size = 0,
|
||||||
|
created = os.epoch('utc'),
|
||||||
|
modification = os.epoch('utc'),
|
||||||
}
|
}
|
||||||
elseif nodeType == 'file' then
|
elseif nodeType == 'file' then
|
||||||
return {
|
return {
|
||||||
size = 0,
|
size = 0,
|
||||||
|
created = os.epoch('utc'),
|
||||||
|
modification = os.epoch('utc'),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
error('ramfs syntax: [directory, file]')
|
error('ramfs syntax: [directory, file]')
|
||||||
end
|
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)
|
function ramfs.delete(node, dir)
|
||||||
if node.mountPoint == dir then
|
if node.mountPoint == dir then
|
||||||
fs.unmount(node.mountPoint)
|
fs.unmount(node.mountPoint)
|
||||||
|
@ -11,6 +11,17 @@ function urlfs.mount(_, url)
|
|||||||
end
|
end
|
||||||
return {
|
return {
|
||||||
url = url,
|
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
|
end
|
||||||
|
|
||||||
|
@ -6,12 +6,11 @@ local Util = require('opus.util')
|
|||||||
|
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
local os = _G.os
|
local os = _G.os
|
||||||
local network = _G.network
|
|
||||||
|
|
||||||
local socketClass = { }
|
local socketClass = { }
|
||||||
|
|
||||||
function socketClass:read(timeout)
|
function socketClass:read(timeout)
|
||||||
local data, distance = network.getTransport().read(self)
|
local data, distance = _G.network.getTransport().read(self)
|
||||||
if data then
|
if data then
|
||||||
return data, distance
|
return data, distance
|
||||||
end
|
end
|
||||||
@ -26,7 +25,7 @@ function socketClass:read(timeout)
|
|||||||
local e, id = os.pullEvent()
|
local e, id = os.pullEvent()
|
||||||
|
|
||||||
if e == 'transport_' .. self.uid then
|
if e == 'transport_' .. self.uid then
|
||||||
data, distance = network.getTransport().read(self)
|
data, distance = _G.network.getTransport().read(self)
|
||||||
if data then
|
if data then
|
||||||
os.cancelTimer(timerId)
|
os.cancelTimer(timerId)
|
||||||
return data, distance
|
return data, distance
|
||||||
@ -47,7 +46,7 @@ end
|
|||||||
|
|
||||||
function socketClass:write(data)
|
function socketClass:write(data)
|
||||||
if self.connected then
|
if self.connected then
|
||||||
network.getTransport().write(self, {
|
_G.network.getTransport().write(self, {
|
||||||
type = 'DATA',
|
type = 'DATA',
|
||||||
seq = self.wseq,
|
seq = self.wseq,
|
||||||
data = data,
|
data = data,
|
||||||
@ -58,7 +57,7 @@ end
|
|||||||
|
|
||||||
function socketClass:ping()
|
function socketClass:ping()
|
||||||
if self.connected then
|
if self.connected then
|
||||||
network.getTransport().ping(self)
|
_G.network.getTransport().ping(self)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -72,7 +71,7 @@ function socketClass:close()
|
|||||||
self.connected = false
|
self.connected = false
|
||||||
end
|
end
|
||||||
device.wireless_modem.close(self.sport)
|
device.wireless_modem.close(self.sport)
|
||||||
network.getTransport().close(self)
|
_G.network.getTransport().close(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
local Socket = { }
|
local Socket = { }
|
||||||
@ -127,9 +126,9 @@ function Socket.connect(host, port, options)
|
|||||||
local socket = newSocket(host == os.getComputerID())
|
local socket = newSocket(host == os.getComputerID())
|
||||||
socket.dhost = tonumber(host)
|
socket.dhost = tonumber(host)
|
||||||
if options and options.keypair then
|
if options and options.keypair then
|
||||||
socket.privKey, socket.pubKey = unpack(options.keypair)
|
socket.privKey, socket.pubKey = table.unpack(options.keypair)
|
||||||
else
|
else
|
||||||
socket.privKey, socket.pubKey = network.getKeyPair()
|
socket.privKey, socket.pubKey = _G.network.getKeyPair()
|
||||||
end
|
end
|
||||||
local identifier = options and options.identifier or Security.getIdentifier()
|
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.remotePubKey = Util.hexToByteArray(msg.pk)
|
||||||
socket.options = msg.options or { }
|
socket.options = msg.options or { }
|
||||||
setupCrypto(socket, true)
|
setupCrypto(socket, true)
|
||||||
network.getTransport().open(socket)
|
_G.network.getTransport().open(socket)
|
||||||
return socket
|
return socket
|
||||||
|
|
||||||
elseif msg.type == 'NOPASS' then
|
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 data and data.ts and tonumber(data.ts) then
|
||||||
if math.abs(os.epoch('utc') - data.ts) < 4096 then
|
if math.abs(os.epoch('utc') - data.ts) < 4096 then
|
||||||
socket.remotePubKey = Util.hexToByteArray(data.pk)
|
socket.remotePubKey = Util.hexToByteArray(data.pk)
|
||||||
socket.privKey, socket.pubKey = network.getKeyPair()
|
socket.privKey, socket.pubKey = _G.network.getKeyPair()
|
||||||
setupCrypto(socket)
|
setupCrypto(socket)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -241,7 +240,7 @@ function Socket.server(port, options)
|
|||||||
options = socket.options.ENCRYPT and { ENCRYPT = true },
|
options = socket.options.ENCRYPT and { ENCRYPT = true },
|
||||||
})
|
})
|
||||||
|
|
||||||
network.getTransport().open(socket)
|
_G.network.getTransport().open(socket)
|
||||||
return socket
|
return socket
|
||||||
|
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user