added comments to applicable functions

This commit is contained in:
Izaya 2019-01-08 18:00:11 +11:00
parent c27b20bc59
commit f6a405d886

View File

@ -2,14 +2,14 @@ fs = {}
fs.mounts = {} fs.mounts = {}
-- basics -- basics
function fs.segments(path) function fs.segments(path) -- splits *path* on each /
local segments = {} local segments = {}
for segment in path:gmatch("[^/]+") do for segment in path:gmatch("[^/]+") do
segments[#segments+1] = segment segments[#segments+1] = segment
end end
return segments return segments
end end
function fs.resolve(path) function fs.resolve(path) -- resolves *path* to a specific filesystem mount and path
if not path or path == "." then path = os.getenv("PWD") end if not path or path == "." then path = os.getenv("PWD") end
if path:sub(1,1) ~= "/" then path=(os.getenv("PWD") or "").."/"..path end if path:sub(1,1) ~= "/" then path=(os.getenv("PWD") or "").."/"..path end
local segments, rpath = fs.segments(path), "/" local segments, rpath = fs.segments(path), "/"
@ -46,7 +46,7 @@ local function fclose(self)
fs.mounts[self.fs].close(self.fid) fs.mounts[self.fs].close(self.fid)
end end
function fs.open(path,mode) function fs.open(path,mode) -- opens file *path* with mode *mode*
mode = mode or "rb" mode = mode or "rb"
local fsi,path = fs.resolve(path) local fsi,path = fs.resolve(path)
if not fs.mounts[fsi] then return false end if not fs.mounts[fsi] then return false end
@ -63,7 +63,7 @@ function fs.open(path,mode)
return false return false
end end
function fs.copy(from,to) function fs.copy(from,to) -- copies a file from *from* to *to*
local of = fs.open(from,"rb") local of = fs.open(from,"rb")
local df = fs.open(to,"wb") local df = fs.open(to,"wb")
if not of or not df then if not of or not df then
@ -74,7 +74,7 @@ function fs.copy(from,to)
of:close() of:close()
end end
function fs.rename(from,to) function fs.rename(from,to) -- moves file *from* to *to*
local ofsi, opath = fs.resolve(from) local ofsi, opath = fs.resolve(from)
local dfsi, dpath = fs.resolve(to) local dfsi, dpath = fs.resolve(to)
if ofsi == dfsi then if ofsi == dfsi then