Skip to content
Snippets Groups Projects
Commit 746ff9fc authored by Ilya's avatar Ilya Committed by Konstantin Osipov
Browse files

fio: improve pathjoin

Add an ability to treat single '/' as no-op.
Ignore duplicate '/' in pathjoin.

Closes #2968
parent f1167c42
No related branches found
No related tags found
No related merge requests found
......@@ -212,16 +212,15 @@ fio.pathjoin = function(path, ...)
if sp == nil then
error("Undefined path part")
end
if sp == '' or sp == '/' then
if sp == '' then
error("Empty path part")
end
if string.match(sp, '^/') ~= nil then
sp = string.gsub(sp, '^/', '')
end
if sp ~= '' then
path = path .. '/' .. sp
end
end
path = string.gsub(path, "/+",'/')
if string.match(path, '/$') ~= nil and #path > 1 then
path = string.gsub(path, '/$', '')
end
......
......@@ -44,6 +44,14 @@ fio.pathjoin('/', '/cde')
---
- /cde
...
fio.pathjoin('/a', '/')
---
- /a
...
fio.pathjoin('abc', 'awdeq///qweqwqwe///', "//asda//")
---
- abc/awdeq/qweqwqwe/asda
...
-- basename
st, err = pcall(fio.basename, nil)
---
......
......@@ -15,6 +15,8 @@ fio.pathjoin('abc', 'cde')
fio.pathjoin('/', 'abc')
fio.pathjoin('abc/', '/cde')
fio.pathjoin('/', '/cde')
fio.pathjoin('/a', '/')
fio.pathjoin('abc', 'awdeq///qweqwqwe///', "//asda//")
-- basename
st, err = pcall(fio.basename, nil)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment