1
0
mirror of https://github.com/kepler155c/opus synced 2025-11-04 17:43:01 +00:00

better fuzzy matching + vfs type flag in Files

This commit is contained in:
kepler155c@gmail.com
2020-05-19 17:09:10 -06:00
parent b93d69c261
commit 985830fcfd
8 changed files with 115 additions and 66 deletions

View File

@@ -166,6 +166,13 @@ function fs.complete(partial, dir, includeFiles, includeSlash)
return fs.native.complete(partial, dir, includeFiles, includeSlash)
end
local displayFlags = {
urlfs = 'U',
linkfs = 'L',
ramfs = 'T',
netfs = 'N',
}
function fs.listEx(dir)
dir = fs.combine(dir, '')
local node = getNode(dir)
@@ -176,20 +183,22 @@ function fs.listEx(dir)
local t = { }
local files = node.fs.list(node, dir)
pcall(function()
for _,f in ipairs(files) do
for _,f in ipairs(files) do
pcall(function()
local fullName = fs.combine(dir, f)
local n = fs.getNode(fullName)
local file = {
name = f,
isDir = fs.isDir(fullName),
isReadOnly = fs.isReadOnly(fullName),
fstype = n.mountPoint == fullName and displayFlags[n.fstype],
}
if not file.isDir then
file.size = fs.getSize(fullName)
end
table.insert(t, file)
end
end)
end)
end
return t
end

View File

@@ -6,37 +6,41 @@ 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'
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)
if not cmd then
return env.shell and 1 or 0
end
local env = _G.getfenv(2)
local s, m = env.shell.run('sys/apps/shell.lua ' .. cmd)
if not env.shell then
return 0
end
if not s then
return 1, m
end
local s, m = env.shell.run('sys/apps/shell.lua ' .. cmd)
return 0
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)
local fname
repeat
fname = 'tmp/a' .. math.random(1, 32768)
until not fs.exists(fname)
return fname
return fname
end
-- non-standard - will raise error instead
os.exit = function(code)
error('Terminated with ' .. code)
error('Terminated with ' .. code)
end

View File

@@ -13,7 +13,13 @@ table.insert(helpPaths, '/sys/help')
for name in pairs(Packages:installed()) do
local packageDir = fs.combine('packages', name)
local fstabPath = fs.combine(packageDir, 'etc/fstab')
if fs.exists(fstabPath) then
fs.loadTab(fstabPath)
end
table.insert(appPaths, 1, '/' .. packageDir)
local apiPath = fs.combine(packageDir, 'apis') -- TODO: rename dir to 'modules' (someday)
if fs.exists(apiPath) then
fs.mount(fs.combine('rom/modules/main', name), 'linkfs', apiPath)
@@ -23,11 +29,6 @@ for name in pairs(Packages:installed()) do
if fs.exists(helpPath) then
table.insert(helpPaths, helpPath)
end
local fstabPath = fs.combine(packageDir, 'etc/fstab')
if fs.exists(fstabPath) then
fs.loadTab(fstabPath)
end
end
help.setPath(table.concat(helpPaths, ':'))