mirror of
https://github.com/kepler155c/opus
synced 2024-12-31 19:00: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:
parent
c7c594d6c3
commit
a7e3318226
@ -52,8 +52,8 @@ local function run(...)
|
|||||||
loadFn = loadfile
|
loadFn = loadfile
|
||||||
end
|
end
|
||||||
|
|
||||||
local bill, err = loadFn(path, env)
|
local funkshun, err = loadFn(path, env)
|
||||||
if not bill then
|
if not funkshun then
|
||||||
error(err, -1)
|
error(err, -1)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ local function run(...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
env[ "arg" ] = { [0] = path, table.unpack(args) }
|
env[ "arg" ] = { [0] = path, table.unpack(args) }
|
||||||
local r = { bill(table.unpack(args)) }
|
local r = { funkshun(table.unpack(args)) }
|
||||||
|
|
||||||
tProgramStack[#tProgramStack] = nil
|
tProgramStack[#tProgramStack] = nil
|
||||||
|
|
||||||
@ -659,7 +659,7 @@ local function shellRead(history)
|
|||||||
return entry.value or ''
|
return entry.value or ''
|
||||||
end
|
end
|
||||||
|
|
||||||
local history = History.load('usr/.shell_history', 25)
|
local history = History.load('usr/.shell_history', 100)
|
||||||
|
|
||||||
term.setBackgroundColor(_colors.backgroundColor)
|
term.setBackgroundColor(_colors.backgroundColor)
|
||||||
--term.clear()
|
--term.clear()
|
||||||
|
@ -100,26 +100,6 @@ end
|
|||||||
function nativefs.delete(node, dir)
|
function nativefs.delete(node, dir)
|
||||||
if node.mountPoint == dir then
|
if node.mountPoint == dir then
|
||||||
fs.unmount(dir)
|
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
|
else
|
||||||
fs.native.delete(dir)
|
fs.native.delete(dir)
|
||||||
end
|
end
|
||||||
@ -316,11 +296,6 @@ function fs.mount(path, fstype, ...)
|
|||||||
end
|
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)
|
||||||
|
|
||||||
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].nodes = { }
|
||||||
tp.nodes[d].mountPoint = fs.combine(tp.mountPoint, d)
|
tp.nodes[d].mountPoint = fs.combine(tp.mountPoint, d)
|
||||||
end
|
end
|
||||||
|
@ -1,3 +1,42 @@
|
|||||||
local fs = _G.fs
|
local fs = _G.fs
|
||||||
|
local os = _G.os
|
||||||
|
|
||||||
fs.loadTab('sys/etc/fstab')
|
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
|
||||||
|
@ -144,6 +144,9 @@ function multishell.openTab(env, tab)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if tab.chainExit then
|
||||||
|
tab.chainExit(self, result, err, stack)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local routine, message = kernel.run(env, tab)
|
local routine, message = kernel.run(env, tab)
|
||||||
|
@ -5,7 +5,7 @@ local linkfs = { }
|
|||||||
-- TODO: implement broken links
|
-- TODO: implement broken links
|
||||||
|
|
||||||
local methods = { 'exists', 'getFreeSpace', 'getSize', 'attributes',
|
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
|
for _,m in pairs(methods) do
|
||||||
linkfs[m] = function(node, dir, ...)
|
linkfs[m] = function(node, dir, ...)
|
||||||
@ -18,7 +18,7 @@ function linkfs.resolve(node, dir)
|
|||||||
return dir:gsub(node.mountPoint, node.source, 1)
|
return dir:gsub(node.mountPoint, node.source, 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
function linkfs.mount(_, source)
|
function linkfs.mount(path, source)
|
||||||
if not source then
|
if not source then
|
||||||
error('Source is required')
|
error('Source is required')
|
||||||
end
|
end
|
||||||
@ -26,6 +26,9 @@ function linkfs.mount(_, source)
|
|||||||
if not fs.exists(source) then
|
if not fs.exists(source) then
|
||||||
error('Source is missing')
|
error('Source is missing')
|
||||||
end
|
end
|
||||||
|
if path == source then
|
||||||
|
return
|
||||||
|
end
|
||||||
if fs.isDir(source) then
|
if fs.isDir(source) then
|
||||||
return {
|
return {
|
||||||
source = source,
|
source = source,
|
||||||
|
@ -5,15 +5,19 @@ local fs = _G.fs
|
|||||||
|
|
||||||
local urlfs = { }
|
local urlfs = { }
|
||||||
|
|
||||||
function urlfs.mount(_, url)
|
function urlfs.mount(path, url, force)
|
||||||
if not url then
|
if not url then
|
||||||
error('URL is required')
|
error('URL is required')
|
||||||
end
|
end
|
||||||
return {
|
|
||||||
url = url,
|
-- only mount if the file does not exist already
|
||||||
created = os.epoch('utc'),
|
if not fs.exists(path) or force then
|
||||||
modification = os.epoch('utc'),
|
return {
|
||||||
}
|
url = url,
|
||||||
|
created = os.epoch('utc'),
|
||||||
|
modification = os.epoch('utc'),
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function urlfs.attributes(node)
|
function urlfs.attributes(node)
|
||||||
@ -38,7 +42,7 @@ function urlfs.getSize(node)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function urlfs.isReadOnly()
|
function urlfs.isReadOnly()
|
||||||
return true
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function urlfs.isDir()
|
function urlfs.isDir()
|
||||||
|
@ -89,6 +89,7 @@ return function(env)
|
|||||||
os = os,
|
os = os,
|
||||||
string = string,
|
string = string,
|
||||||
table = table,
|
table = table,
|
||||||
|
debug = debug,
|
||||||
},
|
},
|
||||||
loaders = {
|
loaders = {
|
||||||
preloadSearcher,
|
preloadSearcher,
|
||||||
|
Loading…
Reference in New Issue
Block a user