First attempt to treat correctly network volumes

On windows paths belonging to network volumes will be gives like:

\\address\share-name\path

Now the code recognize these paths and treat them correctly.
This commit is contained in:
Francesco Abbate 2021-10-12 14:28:28 +02:00
parent 780c8c6d0d
commit f472c24c73
1 changed files with 24 additions and 5 deletions

View File

@ -282,22 +282,41 @@ end
function common.normalize_path(filename) function common.normalize_path(filename)
if not filename then return end if not filename then return end
local volume
if PATHSEP == '\\' then if PATHSEP == '\\' then
filename = filename:gsub('[/\\]', '\\') filename = filename:gsub('[/\\]', '\\')
local drive, rem = filename:match('^([a-zA-Z])(:.*)') local drive, rem = filename:match('^([a-zA-Z]:\\)(.*)')
filename = drive and drive:upper() .. rem or filename if drive then
volume, filename = drive:upper(), rem
else
drive, rem = filename:match('^(\\\\[^\\]+\\[^\\]+\\)(.*)')
if drive then
volume, filename = drive, rem
end
end
else
local relpath = filename:match('^/(.+)')
if relpath then
volume, filepath = "/", relpath
end
end end
local parts = split_on_slash(filename, PATHSEP) local parts = split_on_slash(filename, PATHSEP)
local accu = {} local accu = {}
for _, part in ipairs(parts) do for _, part in ipairs(parts) do
if part == '..' and #accu > 0 and accu[#accu] ~= ".." then if part == '..' then
if #accu > 0 and accu[#accu] ~= ".." then
table.remove(accu) table.remove(accu)
elseif volume then
error("invalid path " .. volume .. filename)
else
table.insert(accu, part)
end
elseif part ~= '.' then elseif part ~= '.' then
table.insert(accu, part) table.insert(accu, part)
end end
end end
local npath = table.concat(accu, PATHSEP) local npath = table.concat(accu, PATHSEP)
return npath == "" and PATHSEP or npath return (volume or "") .. (npath == "" and PATHSEP or npath)
end end