diff options
author | Philipp Gesang <phg42.2a@gmail.com> | 2014-02-14 18:28:31 +0100 |
---|---|---|
committer | Philipp Gesang <phg42.2a@gmail.com> | 2014-02-14 18:28:31 +0100 |
commit | 5ed9c2a6d45121bdeacdf1c8f4dead50374f0899 (patch) | |
tree | 0e2bbc4ecd17b275133bb89340bbc4218a604b67 /lualibs-dir.lua | |
parent | 43ffeea64e686e25807959575d07162bc8bb02b6 (diff) | |
download | lualibs-5ed9c2a6d45121bdeacdf1c8f4dead50374f0899.tar.gz |
sync with Context as of 2014-02-14
Diffstat (limited to 'lualibs-dir.lua')
-rw-r--r-- | lualibs-dir.lua | 61 |
1 files changed, 41 insertions, 20 deletions
diff --git a/lualibs-dir.lua b/lualibs-dir.lua index 40081cc..b658b7c 100644 --- a/lualibs-dir.lua +++ b/lualibs-dir.lua @@ -25,6 +25,7 @@ local isdir = lfs.isdir local isfile = lfs.isfile local currentdir = lfs.currentdir local chdir = lfs.chdir +local mkdir = lfs.mkdir local onwindows = os.type == "windows" or find(os.getenv("PATH"),";") @@ -284,17 +285,28 @@ local make_indeed = true -- false if onwindows then function dir.mkdirs(...) - local str, pth = "", "" - for i=1,select("#",...) do - local s = select(i,...) - if s == "" then - -- skip - elseif str == "" then - str = s - else - str = str .. "/" .. s + local n = select("#",...) + local str + if n == 1 then + str = select(1,...) + if isdir(str) then + return str, true + end + else + str = "" + for i=1,n do + local s = select(i,...) + local s = select(i,...) + if s == "" then + -- skip + elseif str == "" then + str = s + else + str = str .. "/" .. s + end end end + local pth = "" local drive = false local first, middle, last = match(str,"^(//)(//*)(.*)$") if first then @@ -330,7 +342,7 @@ if onwindows then pth = pth .. "/" .. s end if make_indeed and not isdir(pth) then - lfs.mkdir(pth) + mkdir(pth) end end return pth, (isdir(pth) == true) @@ -351,14 +363,23 @@ if onwindows then else function dir.mkdirs(...) - local str, pth = "", "" - for i=1,select("#",...) do - local s = select(i,...) - if s and s ~= "" then -- we catch nil and false - if str ~= "" then - str = str .. "/" .. s - else - str = s + local n = select("#",...) + local str, pth + if n == 1 then + str = select(1,...) + if isdir(str) then + return str, true + end + else + str = "" + for i=1,n do + local s = select(i,...) + if s and s ~= "" then -- we catch nil and false + if str ~= "" then + str = str .. "/" .. s + else + str = s + end end end end @@ -373,7 +394,7 @@ else pth = pth .. "/" .. s end if make_indeed and not first and not isdir(pth) then - lfs.mkdir(pth) + mkdir(pth) end end else @@ -381,7 +402,7 @@ else for s in gmatch(str,"[^/]+") do pth = pth .. "/" .. s if make_indeed and not isdir(pth) then - lfs.mkdir(pth) + mkdir(pth) end end end |