From 43fc35d7dc802e0cde84ae88fa7fff474a44e9b3 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Tue, 12 Oct 2021 14:28:28 +0200 Subject: [PATCH] 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. --- data/core/common.lua | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/data/core/common.lua b/data/core/common.lua index 1a1b22cd..ebd3df40 100644 --- a/data/core/common.lua +++ b/data/core/common.lua @@ -282,22 +282,41 @@ end function common.normalize_path(filename) if not filename then return end + local volume if PATHSEP == '\\' then filename = filename:gsub('[/\\]', '\\') - local drive, rem = filename:match('^([a-zA-Z])(:.*)') - filename = drive and drive:upper() .. rem or filename + local drive, rem = filename:match('^([a-zA-Z]:\\)(.*)') + 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 local parts = split_on_slash(filename, PATHSEP) local accu = {} for _, part in ipairs(parts) do - if part == '..' and #accu > 0 and accu[#accu] ~= ".." then - table.remove(accu) + if part == '..' then + if #accu > 0 and accu[#accu] ~= ".." then + table.remove(accu) + elseif volume then + error("invalid path " .. volume .. filename) + else + table.insert(accu, part) + end elseif part ~= '.' then table.insert(accu, part) end end local npath = table.concat(accu, PATHSEP) - return npath == "" and PATHSEP or npath + return (volume or "") .. (npath == "" and PATHSEP or npath) end