summaryrefslogtreecommitdiffstats
path: root/acf/persistence/backends/files.lua
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2013-06-27 20:18:54 +0300
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2013-06-28 13:24:36 +0300
commit5c960909594d1978f45968f8155ab2afab381298 (patch)
tree40d6de63ce5818a46b05794a4596329c28d4bd5f /acf/persistence/backends/files.lua
parent0d5dade5ab61e5cfd3116893aadcb9b16ba5cfb5 (diff)
downloadaconf-5c960909594d1978f45968f8155ab2afab381298.tar.bz2
aconf-5c960909594d1978f45968f8155ab2afab381298.tar.xz
eliminate data type arguments from transaction and persistence manager intefaces
utilize model topology information instead
Diffstat (limited to 'acf/persistence/backends/files.lua')
-rw-r--r--acf/persistence/backends/files.lua53
1 files changed, 33 insertions, 20 deletions
diff --git a/acf/persistence/backends/files.lua b/acf/persistence/backends/files.lua
index f0ac5a6..782674d 100644
--- a/acf/persistence/backends/files.lua
+++ b/acf/persistence/backends/files.lua
@@ -5,19 +5,32 @@ See LICENSE file for license details
module(..., package.seeall)
+local topology = require('acf.model.root').topology
local pth = require('acf.path')
local util = require('acf.persistence.util')
+local copy = require('acf.util').copy
require 'posix'
require 'stringy'
+local function get_scope(top)
+ if not top or top.type ~= 'reference' or not pth.is_unique(top.scope) then
+ return
+ end
+
+ return stringy.startswith(top.scope, '/files/') and string.sub(
+ top.scope, 7, -1
+ ) or nil
+end
+
+
backend = require('acf.object').class()
-- TODO cache expiration
function backend:init() self.cache = {} end
-function backend:get(path, tpe)
+function backend:get(path, top)
local name = pth.join('/', unpack(path))
if not self.cache[name] then
@@ -31,10 +44,10 @@ function backend:get(path, tpe)
-- TODO handle relative symlinks
local target = posix.readlink(name)
assert(target)
- if not tpe then return target end
- assert(stringy.startswith(tpe, 'reference/files/'))
- local scope = string.sub(tpe, 16, -1)..'/'
+ local scope = get_scope(top)
+ assert(scope)
+ scope = scope..'/'
local slen = string.len(scope)
assert(string.sub(target, 1, slen) == scope)
@@ -57,10 +70,10 @@ end
function backend:set(mods)
for _, mod in pairs(mods) do
- local path, tpe, value = unpack(mod)
+ local path, value = unpack(mod)
local name = pth.join('/', unpack(path))
- if not tpe then
+ if value == nil then
print('DEL', name)
local t = posix.stat(name, 'type')
@@ -70,24 +83,24 @@ function backend:set(mods)
self.cache[name] = nil
- elseif tpe == 'table' then
+ elseif type(value) == 'table' then
assert(posix.mkdir(name))
- elseif stringy.startswith(tpe, 'reference/files/') then
- -- TODO use relative symlink
- os.remove(name)
- assert(
- posix.link(
- pth.to_absolute(value, string.sub(tpe, 16, -1)), name, true
- )
- )
-
else
- local file = util.open_file(name, 'w')
- file:write(tostring(value))
- file:close()
+ local scope = get_scope(topology('/files'..name))
+
+ if scope then
+ -- TODO use relative symlink
+ os.remove(name)
+ assert(posix.link(pth.to_absolute(value, scope), name, true))
- self.cache[name] = value
+ else
+ local file = util.open_file(name, 'w')
+ file:write(tostring(value))
+ file:close()
+
+ self.cache[name] = value
+ end
end
end
end