Refactor linkfs and netfs resolve functions for improved path handling
This commit is contained in:
@@ -15,7 +15,11 @@ for _,m in pairs(methods) do
|
|||||||
end
|
end
|
||||||
|
|
||||||
function linkfs.resolve(node, dir)
|
function linkfs.resolve(node, dir)
|
||||||
return dir:gsub(node.mountPoint, node.source, 1)
|
local mp = node.mountPoint
|
||||||
|
if dir:sub(1, #mp) == mp then
|
||||||
|
return node.source .. dir:sub(#mp + 1)
|
||||||
|
end
|
||||||
|
return dir
|
||||||
end
|
end
|
||||||
|
|
||||||
function linkfs.mount(path, source)
|
function linkfs.mount(path, source)
|
||||||
@@ -41,8 +45,8 @@ function linkfs.mount(path, source)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function linkfs.copy(node, s, t)
|
function linkfs.copy(node, s, t)
|
||||||
s = s:gsub(node.mountPoint, node.source, 1)
|
s = linkfs.resolve(node, s)
|
||||||
t = t:gsub(node.mountPoint, node.source, 1)
|
t = linkfs.resolve(node, t)
|
||||||
return fs.copy(s, t)
|
return fs.copy(s, t)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -50,25 +54,29 @@ function linkfs.delete(node, dir)
|
|||||||
if dir == node.mountPoint then
|
if dir == node.mountPoint then
|
||||||
fs.unmount(node.mountPoint)
|
fs.unmount(node.mountPoint)
|
||||||
else
|
else
|
||||||
dir = dir:gsub(node.mountPoint, node.source, 1)
|
dir = linkfs.resolve(node, dir)
|
||||||
return fs.delete(dir)
|
return fs.delete(dir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function linkfs.find(node, spec)
|
function linkfs.find(node, spec)
|
||||||
spec = spec:gsub(node.mountPoint, node.source, 1)
|
spec = linkfs.resolve(node, spec)
|
||||||
|
|
||||||
local list = fs.find(spec)
|
local list = fs.find(spec)
|
||||||
|
local src = node.source
|
||||||
|
local mp = node.mountPoint
|
||||||
for k,f in ipairs(list) do
|
for k,f in ipairs(list) do
|
||||||
list[k] = f:gsub(node.source, node.mountPoint, 1)
|
if f:sub(1, #src) == src then
|
||||||
|
list[k] = mp .. f:sub(#src + 1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return list
|
return list
|
||||||
end
|
end
|
||||||
|
|
||||||
function linkfs.move(node, s, t)
|
function linkfs.move(node, s, t)
|
||||||
s = s:gsub(node.mountPoint, node.source, 1)
|
s = linkfs.resolve(node, s)
|
||||||
t = t:gsub(node.mountPoint, node.source, 1)
|
t = linkfs.resolve(node, t)
|
||||||
return fs.move(s, t)
|
return fs.move(s, t)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -35,8 +35,10 @@ end
|
|||||||
local methods = { 'delete', 'exists', 'getFreeSpace', 'makeDir', 'list', 'listEx', 'attributes' }
|
local methods = { 'delete', 'exists', 'getFreeSpace', 'makeDir', 'list', 'listEx', 'attributes' }
|
||||||
|
|
||||||
local function resolve(node, dir)
|
local function resolve(node, dir)
|
||||||
-- TODO: Wrong ! (does not support names with dashes)
|
local mp = node.mountPoint
|
||||||
dir = dir:gsub(node.mountPoint, '', 1)
|
if dir:sub(1, #mp) == mp then
|
||||||
|
dir = dir:sub(#mp + 1)
|
||||||
|
end
|
||||||
return fs.combine(node.source, dir)
|
return fs.combine(node.source, dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -53,7 +55,7 @@ end
|
|||||||
|
|
||||||
function netfs.mount(_, id, source)
|
function netfs.mount(_, id, source)
|
||||||
if not id or not tonumber(id) then
|
if not id or not tonumber(id) then
|
||||||
error('ramfs syntax: computerId [directory]')
|
error('netfs syntax: computerId [directory]')
|
||||||
end
|
end
|
||||||
return {
|
return {
|
||||||
id = tonumber(id),
|
id = tonumber(id),
|
||||||
|
|||||||
Reference in New Issue
Block a user