1
0
mirror of https://github.com/ShadowKatStudios/OC-Minitel.git synced 2024-11-23 10:38:05 +11:00

refactored importfs to use one function for all cache access

This commit is contained in:
Izaya 2020-10-12 19:20:22 +11:00
parent a3601bc0a3
commit 11d6966a8a

View File

@ -36,36 +36,25 @@ if px.dirstat then -- use single call for file info
return rt return rt
end end
local oid, osize, olm = px.isDirectory, px.size, px.lastModified local oid, osize, olm = px.isDirectory, px.size, px.lastModified
local function cc() -- clean the cache of old entries local function gce(p,n)
for k,v in pairs(statcache) do for k,v in pairs(statcache) do
if computer.uptime() > v[1] + 1 then if computer.uptime() > v[1] + 1 then
statcache[k] = nil statcache[k] = nil
end end
end end
local ci = statcache["/"..fs.canonical(p)]
if ci then
return ci[3]
end
end end
function px.isDirectory(path) function px.isDirectory(path)
cc() return gce(path, 2) or oid(path)
local ci = statcache["/"..fs.canonical(path)]
if ci then
return ci[3]
end
return oid(path)
end end
function px.size(path) function px.size(path)
cc() return gce(path, 3) or osize(path)
local ci = statcache["/"..fs.canonical(path)]
if ci then
return ci[2]
end
return osize(path)
end end
function px.lastModified(path) function px.lastModified(path)
cc() return gce(path, 4) or olm(path)
local ci = statcache["/"..fs.canonical(path)]
if ci then
return ci[3]
end
return olm(path)
end end
end end
fs.mount(px, lpath) fs.mount(px, lpath)