1
0
mirror of https://github.com/kepler155c/opus synced 2024-11-20 07:34:50 +00:00
opus/sys/apis/fs/linkfs.lua

64 lines
1.2 KiB
Lua
Raw Normal View History

2017-10-08 21:45:01 +00:00
local fs = _G.fs
2016-12-11 19:24:52 +00:00
local linkfs = { }
2017-10-08 21:45:01 +00:00
local methods = { 'exists', 'getFreeSpace', 'getSize',
2018-01-24 22:39:38 +00:00
'isDir', 'isReadOnly', 'list', 'listEx', 'makeDir', 'open', 'getDrive' }
2016-12-11 19:24:52 +00:00
for _,m in pairs(methods) do
2018-01-24 22:39:38 +00:00
linkfs[m] = function(node, dir, ...)
dir = dir:gsub(node.mountPoint, node.source, 1)
return fs[m](dir, ...)
end
2016-12-11 19:24:52 +00:00
end
2017-10-08 21:45:01 +00:00
function linkfs.mount(_, source)
2018-01-24 22:39:38 +00:00
if not source then
error('Source is required')
end
source = fs.combine(source, '')
if fs.isDir(source) then
return {
source = source,
nodes = { },
}
end
return {
source = source
}
2016-12-11 19:24:52 +00:00
end
function linkfs.copy(node, s, t)
2018-01-24 22:39:38 +00:00
s = s:gsub(node.mountPoint, node.source, 1)
t = t:gsub(node.mountPoint, node.source, 1)
return fs.copy(s, t)
2016-12-11 19:24:52 +00:00
end
function linkfs.delete(node, dir)
2018-01-24 22:39:38 +00:00
if dir == node.mountPoint then
fs.unmount(node.mountPoint)
else
dir = dir:gsub(node.mountPoint, node.source, 1)
return fs.delete(dir)
end
2016-12-11 19:24:52 +00:00
end
function linkfs.find(node, spec)
2018-01-24 22:39:38 +00:00
spec = spec:gsub(node.mountPoint, node.source, 1)
2016-12-11 19:24:52 +00:00
2018-01-24 22:39:38 +00:00
local list = fs.find(spec)
for k,f in ipairs(list) do
list[k] = f:gsub(node.source, node.mountPoint, 1)
end
2016-12-11 19:24:52 +00:00
2018-01-24 22:39:38 +00:00
return list
2016-12-11 19:24:52 +00:00
end
function linkfs.move(node, s, t)
2018-01-24 22:39:38 +00:00
s = s:gsub(node.mountPoint, node.source, 1)
t = t:gsub(node.mountPoint, node.source, 1)
return fs.move(s, t)
2016-12-11 19:24:52 +00:00
end
return linkfs