summaryrefslogtreecommitdiffstats
path: root/aconf/persistence/backends
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2015-03-10 21:11:19 +0200
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2015-03-11 16:54:19 +0200
commit31bd7bd491738d8653a9e181594969a3665aca22 (patch)
treeb8710c5554c89bd698520fa3f2b80ef1faf454f1 /aconf/persistence/backends
parent2d58b8f49ec03fe3d4ad843085ffe09880e3f888 (diff)
downloadaconf-31bd7bd491738d8653a9e181594969a3665aca22.tar.bz2
aconf-31bd7bd491738d8653a9e181594969a3665aca22.tar.xz
persistence: move augeas back-end directives out of addresses
Diffstat (limited to 'aconf/persistence/backends')
-rw-r--r--aconf/persistence/backends/augeas.lua36
1 files changed, 23 insertions, 13 deletions
diff --git a/aconf/persistence/backends/augeas.lua b/aconf/persistence/backends/augeas.lua
index 2679371..2210346 100644
--- a/aconf/persistence/backends/augeas.lua
+++ b/aconf/persistence/backends/augeas.lua
@@ -49,12 +49,20 @@ local function key(mode) return mode.key or '.' end
+local function aug_top(path)
+ path = copy(path)
+ table.insert(path, 1, 'augeas')
+ return topology(path)
+end
+
+
local function conv_path(path)
local res = '/files'
if #path == 0 then return res, nil, {} end
path = copy(path)
- local mode
+ local top = aug_top{}
+ local mode, parent
local keys = {}
repeat
@@ -70,26 +78,27 @@ local function conv_path(path)
res = append_key_pred(res, k, comp)
table.insert(keys, k)
else assert(false) end
- mode = nil
- elseif isinstance(comp, special.SpecialMode) then mode = comp
+ parent = nil
else
+ parent = res
res = res..'/'..comp
keys = {}
end
+ top = top and top(address.escape(comp))
+ mode = top and top.mode
+
table.remove(path, 1)
until #path == 0
- return res, mode, isinstance(mode, special.Value) and {} or keys
-end
-
+ if isinstance(mode, special.Value) then
+ assert(parent)
+ res = parent
+ end
-local function aug_top(path)
- path = copy(path)
- table.insert(path, 1, 'augeas')
- return topology(path)
+ return res, mode, keys
end
@@ -104,6 +113,8 @@ function backend:get(path, top)
local tpe = top and top.type
local tbl = tpe == 'table'
+ if tbl and top.subtype == 'model' then mode = nil end
+
local leaf = not tbl and not mode
if isinstance(mode, special.Value) then
assert(not tbl)
@@ -116,7 +127,7 @@ function backend:get(path, top)
if #matches == 0 and not is_selector then return end
if is_selector and #path > 1 and not self:get(
- array_without_last(array_without_last(path)), true
+ array_without_last(path), true
) then
return
end
@@ -170,7 +181,6 @@ function backend:set(mods)
local function insert(path, new)
local apath, mode, keys = conv_path(path)
- if mode then path[#path] = nil end
if #path == 0 then return apath, keys end
local name = path[#path]
@@ -178,7 +188,7 @@ function backend:set(mods)
local ppath, pmode = conv_path(parent)
if isinstance(pmode, special.Selector) then
- gc[address.join('/', table.unpack(array_without_last(parent)))] = false
+ gc[address.join('/', table.unpack(parent))] = false
if isinstance(pmode, special.EnumKeys) then
local count = #self.aug:match(ppath)