--[[ Copyright (c) 2012-2013 Kaarle Ritvanen See LICENSE file for license details --]] module(..., package.seeall) local pth = require('acf.path') local util = require('acf.persistence.util') require 'posix' backend = require('acf.object').class() -- TODO cache expiration function backend:init() self.cache = {} end function backend:get(path, tpe) local name = pth.mjoin('/', unpack(path)) if not self.cache[name] then local t = posix.stat(name, 'type') if not t then return end if t == 'regular' then self.cache[name] = util.read_file(name) elseif t == 'directory' then local res = {} for _, fname in ipairs(posix.dir(name)) do if not ({['.']=true, ['..']=true})[fname] then table.insert(res, fname) end end return res else error('Unsupported file type: '..name) end -- TODO present symlinks as references end return self.cache[name] end function backend:set(mods) for _, mod in pairs(mods) do local path, t, value = unpack(mod) local name = pth.mjoin('/', unpack(path)) -- TODO save references (t == 'reference') as symlinks if not t then -- TODO del files & dirs print('DEL', name) elseif t == 'table' then assert(posix.mkdir(name)) else local file = util.open_file(name, 'w') file:write(tostring(value)) file:close() self.cache[name] = value end end end