fixed path resolving and a few functions

This commit is contained in:
Izaya 2017-08-01 15:45:22 +10:00
parent e94916e4ab
commit 2aa6976c32
1 changed files with 19 additions and 6 deletions

View File

@ -27,11 +27,17 @@ do
p=(os.getenv("PWD") or "").."/"..p
end
p=fs.simplify(p)
local pt = {}
local pt,spt = {},""
for P in p:gmatch("[^/]+") do
pt[#pt+1] = P
end
return pt, p:match("/?(.-)/"), p:match("/?.-/(.+)")
for i = 2, #pt do
spt=spt..pt[i]
end
return pt, pt[1], spt
end
function fs.exec(fc,m,...)
return fT[fc][m](...)
end
function fs.open(p,m)
local _,d,p = fs.resolve(p)
@ -70,8 +76,15 @@ do
end
return false
end
function fs.list(s)
function fs.list(s)
local _,d,p = fs.resolve(s)
if not d then
local kt = {}
for k,v in pairs(fT) do
kt[#kt+1] = k
end
return kt
end
return fT[d].list(p or "/")
end
function fs.mkdir(s)
@ -79,15 +92,15 @@ do
return fT[d].makeDirectory(p or "/")
end
function fs.rm(s)
local d,p = fs.resolve(s)
local _,d,p = fs.resolve(s)
return fT[d].remove(p)
end
function fs.exists(s)
local d,p = fs.resolve(s)
local _,d,p = fs.resolve(s)
return fT[d].exists(p)
end
function fs.isdir(s)
local d,p = fs.resolve(s)
local _,d,p = fs.resolve(s)
return fT[d].isDirectory(p)
end
end