* ffluci/core: fs.lua: add wrapper for mkdir() to allow recursive creation of directory paths; whitespace cleanup
This commit is contained in:
parent
e53d31062e
commit
0200ca38eb
1 changed files with 43 additions and 12 deletions
|
@ -79,8 +79,39 @@ dirname = posix.dirname
|
|||
-- dir wrapper
|
||||
dir = posix.dir
|
||||
|
||||
-- Alias for posix.mkdir
|
||||
mkdir = posix.mkdir
|
||||
-- wrapper for posix.mkdir
|
||||
function mkdir(path, recursive)
|
||||
if recursive then
|
||||
local base = "."
|
||||
|
||||
if path:sub(1,1) == "/" then
|
||||
base = ""
|
||||
path = path:gsub("^/+","")
|
||||
end
|
||||
|
||||
for elem in path:gmatch("([^/]+)/*") do
|
||||
base = base .. "/" .. elem
|
||||
|
||||
local stat = posix.stat( base )
|
||||
|
||||
if not stat then
|
||||
local stat, errmsg, errno = posix.mkdir( base )
|
||||
|
||||
if type(stat) ~= "number" or stat ~= 0 then
|
||||
return stat, errmsg, errno
|
||||
end
|
||||
else
|
||||
if stat.type ~= "directory" then
|
||||
return nil, base .. ": File exists", 17
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return 0
|
||||
else
|
||||
return posix.mkdir( path )
|
||||
end
|
||||
end
|
||||
|
||||
-- Alias for posix.rmdir
|
||||
rmdir = posix.rmdir
|
||||
|
|
Loading…
Reference in a new issue