diff --git a/sys/apps/Lua.lua b/sys/apps/Lua.lua index 352606e..557573c 100644 --- a/sys/apps/Lua.lua +++ b/sys/apps/Lua.lua @@ -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(...) diff --git a/sys/apps/package.lua b/sys/apps/package.lua index b5fdba3..324d321 100644 --- a/sys/apps/package.lua +++ b/sys/apps/package.lua @@ -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 diff --git a/sys/init/2.vfs.lua b/sys/init/2.vfs.lua index bc1dc96..3361d80 100644 --- a/sys/init/2.vfs.lua +++ b/sys/init/2.vfs.lua @@ -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 diff --git a/sys/modules/opus/fs/linkfs.lua b/sys/modules/opus/fs/linkfs.lua index 79ec13d..8ffdb4c 100644 --- a/sys/modules/opus/fs/linkfs.lua +++ b/sys/modules/opus/fs/linkfs.lua @@ -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') diff --git a/sys/modules/opus/fs/netfs.lua b/sys/modules/opus/fs/netfs.lua index e36a1cc..5fed98d 100644 --- a/sys/modules/opus/fs/netfs.lua +++ b/sys/modules/opus/fs/netfs.lua @@ -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', diff --git a/sys/modules/opus/fs/ramfs.lua b/sys/modules/opus/fs/ramfs.lua index a516d80..9681b0d 100644 --- a/sys/modules/opus/fs/ramfs.lua +++ b/sys/modules/opus/fs/ramfs.lua @@ -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) diff --git a/sys/modules/opus/fs/urlfs.lua b/sys/modules/opus/fs/urlfs.lua index 3595cb3..96b7854 100644 --- a/sys/modules/opus/fs/urlfs.lua +++ b/sys/modules/opus/fs/urlfs.lua @@ -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 diff --git a/sys/modules/opus/socket.lua b/sys/modules/opus/socket.lua index 89afa4b..8aad0c9 100644 --- a/sys/modules/opus/socket.lua +++ b/sys/modules/opus/socket.lua @@ -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