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

View File

@ -27,11 +27,17 @@ do
p=(os.getenv("PWD") or "").."/"..p p=(os.getenv("PWD") or "").."/"..p
end end
p=fs.simplify(p) p=fs.simplify(p)
local pt = {} local pt,spt = {},""
for P in p:gmatch("[^/]+") do for P in p:gmatch("[^/]+") do
pt[#pt+1] = P pt[#pt+1] = P
end 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 end
function fs.open(p,m) function fs.open(p,m)
local _,d,p = fs.resolve(p) local _,d,p = fs.resolve(p)
@ -70,8 +76,15 @@ do
end end
return false return false
end end
function fs.list(s) function fs.list(s)
local _,d,p = fs.resolve(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 "/") return fT[d].list(p or "/")
end end
function fs.mkdir(s) function fs.mkdir(s)
@ -79,15 +92,15 @@ do
return fT[d].makeDirectory(p or "/") return fT[d].makeDirectory(p or "/")
end end
function fs.rm(s) function fs.rm(s)
local d,p = fs.resolve(s) local _,d,p = fs.resolve(s)
return fT[d].remove(p) return fT[d].remove(p)
end end
function fs.exists(s) function fs.exists(s)
local d,p = fs.resolve(s) local _,d,p = fs.resolve(s)
return fT[d].exists(p) return fT[d].exists(p)
end end
function fs.isdir(s) function fs.isdir(s)
local d,p = fs.resolve(s) local _,d,p = fs.resolve(s)
return fT[d].isDirectory(p) return fT[d].isDirectory(p)
end end
end end