diff --git a/disklock.lua b/disklock.lua index 231418c..82b9346 100644 --- a/disklock.lua +++ b/disklock.lua @@ -28,13 +28,14 @@ local function deepcopy(o, seen) end local realfs = deepcopy(fs) -local function getRom(path) - if not path then path = "/rom" end +local rom_cache = nil + +local function buildRom(path) local out = {} - for _,file in ipairs(realfs.list(path)) do - local fullPath = realfs.combine(path, file) -- use realfs here to avoid recursing into _G.fs + for _, file in ipairs(realfs.list(path)) do + local fullPath = realfs.combine(path, file) if realfs.isDir(fullPath) then - out[file] = getRom(fullPath) + out[file] = buildRom(fullPath) else local handle = realfs.open(fullPath, "r") out[file] = handle.readAll() @@ -44,6 +45,13 @@ local function getRom(path) return out end +local function getRom() + if not rom_cache then + rom_cache = buildRom("/rom") + end + return rom_cache +end + local function getFileSystem() if filesystem then filesystem.rom = getRom() return filesystem end if not realfs.exists("fs") then