1
0
mirror of https://github.com/kepler155c/opus synced 2024-12-29 01:50:27 +00:00

add standard lua os methods, another fix for vfs links within links, allow write on urlfs mounted files

This commit is contained in:
kepler155c@gmail.com 2020-05-17 19:36:33 -06:00
parent c7c594d6c3
commit a7e3318226
7 changed files with 64 additions and 39 deletions

View File

@ -52,8 +52,8 @@ local function run(...)
loadFn = loadfile
end
local bill, err = loadFn(path, env)
if not bill then
local funkshun, err = loadFn(path, env)
if not funkshun then
error(err, -1)
end
@ -68,7 +68,7 @@ local function run(...)
}
env[ "arg" ] = { [0] = path, table.unpack(args) }
local r = { bill(table.unpack(args)) }
local r = { funkshun(table.unpack(args)) }
tProgramStack[#tProgramStack] = nil
@ -659,7 +659,7 @@ local function shellRead(history)
return entry.value or ''
end
local history = History.load('usr/.shell_history', 25)
local history = History.load('usr/.shell_history', 100)
term.setBackgroundColor(_colors.backgroundColor)
--term.clear()

View File

@ -100,26 +100,6 @@ end
function nativefs.delete(node, dir)
if node.mountPoint == dir then
fs.unmount(dir)
-- hack here
-- if a file is mounted over an existing directory
-- ie. sys/apps/MOUNT.LUA
-- then sys and sys/apps are created as temp nodes
-- therefore, trying to delete sys was only
-- removing the node and not deleting the directory
-- Need a better way to backfill nodes in a way
-- that preserves the vfs functionality
-- perhaps a flag that denotes that this
-- file/directory is the actual mount
-- this hack will not fix
-- rm packages/common
-- where packages is linked from a drive
-- and urls are mounted under packages/common
-- (as the fstype will be linkfs)
if node.fstype == 'nativefs' then
fs.native.delete(dir)
end
else
fs.native.delete(dir)
end
@ -316,11 +296,6 @@ function fs.mount(path, fstype, ...)
end
if not tp.nodes[d] then
tp.nodes[d] = Util.shallowCopy(tp)
if tp.nodes[d].source then
tp.nodes[d].source = fs.combine(tp.nodes[d].source, d)
end
tp.nodes[d].nodes = { }
tp.nodes[d].mountPoint = fs.combine(tp.mountPoint, d)
end

View File

@ -1,3 +1,42 @@
local fs = _G.fs
local fs = _G.fs
local os = _G.os
fs.loadTab('sys/etc/fstab')
-- add some Lua compatibility functions
function os.remove(a)
if fs.exists(a) then
local s = pcall(fs.delete, a)
return s and true or nil, a .. ': Unable to remove file'
end
return nil, a .. ': No such file or directory'
end
os.execute = function(cmd)
if not cmd then
return 1
end
local env = _G.getfenv(2)
local s, m = env.shell.run('sys/apps/shell.lua ' .. cmd)
if not s then
return 1, m
end
return 0
end
os.tmpname = function()
local fname
repeat
fname = 'tmp/a' .. math.random(1, 32768)
until not fs.exists(fname)
return fname
end
-- non-standard - will raise error instead
os.exit = function(code)
error('Terminated with ' .. code)
end

View File

@ -144,6 +144,9 @@ function multishell.openTab(env, tab)
end
end
end
if tab.chainExit then
tab.chainExit(self, result, err, stack)
end
end
local routine, message = kernel.run(env, tab)

View File

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

View File

@ -5,15 +5,19 @@ local fs = _G.fs
local urlfs = { }
function urlfs.mount(_, url)
function urlfs.mount(path, url, force)
if not url then
error('URL is required')
end
return {
url = url,
created = os.epoch('utc'),
modification = os.epoch('utc'),
}
-- only mount if the file does not exist already
if not fs.exists(path) or force then
return {
url = url,
created = os.epoch('utc'),
modification = os.epoch('utc'),
}
end
end
function urlfs.attributes(node)
@ -38,7 +42,7 @@ function urlfs.getSize(node)
end
function urlfs.isReadOnly()
return true
return false
end
function urlfs.isDir()

View File

@ -89,6 +89,7 @@ return function(env)
os = os,
string = string,
table = table,
debug = debug,
},
loaders = {
preloadSearcher,