Refactor linkfs and netfs resolve functions for improved path handling

This commit is contained in:
MayaTheShy
2026-03-22 04:09:43 -04:00
parent ba49f7ca7d
commit 882894685c
2 changed files with 21 additions and 11 deletions

View File

@@ -15,7 +15,11 @@ for _,m in pairs(methods) do
end
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
function linkfs.mount(path, source)
@@ -41,8 +45,8 @@ function linkfs.mount(path, source)
end
function linkfs.copy(node, s, t)
s = s:gsub(node.mountPoint, node.source, 1)
t = t:gsub(node.mountPoint, node.source, 1)
s = linkfs.resolve(node, s)
t = linkfs.resolve(node, t)
return fs.copy(s, t)
end
@@ -50,25 +54,29 @@ function linkfs.delete(node, dir)
if dir == node.mountPoint then
fs.unmount(node.mountPoint)
else
dir = dir:gsub(node.mountPoint, node.source, 1)
dir = linkfs.resolve(node, dir)
return fs.delete(dir)
end
end
function linkfs.find(node, spec)
spec = spec:gsub(node.mountPoint, node.source, 1)
spec = linkfs.resolve(node, spec)
local list = fs.find(spec)
local src = node.source
local mp = node.mountPoint
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
return list
end
function linkfs.move(node, s, t)
s = s:gsub(node.mountPoint, node.source, 1)
t = t:gsub(node.mountPoint, node.source, 1)
s = linkfs.resolve(node, s)
t = linkfs.resolve(node, t)
return fs.move(s, t)
end

View File

@@ -35,8 +35,10 @@ end
local methods = { 'delete', 'exists', 'getFreeSpace', 'makeDir', 'list', 'listEx', 'attributes' }
local function resolve(node, dir)
-- TODO: Wrong ! (does not support names with dashes)
dir = dir:gsub(node.mountPoint, '', 1)
local mp = node.mountPoint
if dir:sub(1, #mp) == mp then
dir = dir:sub(#mp + 1)
end
return fs.combine(node.source, dir)
end
@@ -53,7 +55,7 @@ end
function netfs.mount(_, id, source)
if not id or not tonumber(id) then
error('ramfs syntax: computerId [directory]')
error('netfs syntax: computerId [directory]')
end
return {
id = tonumber(id),