summaryrefslogtreecommitdiffstats
path: root/aconf/persistence
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2014-06-16 13:06:41 +0300
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2014-06-16 13:06:41 +0300
commit07447880a4e3d336bcdee83d7fbc9901279f92ed (patch)
tree9f549e467635001234e7641f49bdfc23e9902768 /aconf/persistence
parentbc1689c28354efc0968bdd3847d0e011fcb84b88 (diff)
downloadaconf-07447880a4e3d336bcdee83d7fbc9901279f92ed.tar.bz2
aconf-07447880a4e3d336bcdee83d7fbc9901279f92ed.tar.xz
augeas backend: explicit selector for node's value
Diffstat (limited to 'aconf/persistence')
-rw-r--r--aconf/persistence/backends/augeas.lua23
1 files changed, 16 insertions, 7 deletions
diff --git a/aconf/persistence/backends/augeas.lua b/aconf/persistence/backends/augeas.lua
index 7ffccb9..1496d5b 100644
--- a/aconf/persistence/backends/augeas.lua
+++ b/aconf/persistence/backends/augeas.lua
@@ -9,6 +9,7 @@ local pth = require('aconf.path')
local tostr = require('aconf.persistence.util').tostring
local util = require('aconf.util')
+local contains = util.contains
local copy = util.copy
@@ -41,6 +42,8 @@ local function append_pred(path, pred) return path..'['..pred..']' end
local function key_mode(mode) return mode and stringy.startswith(mode, '@') end
+local function tbl_mode(mode) return mode == '#' or key_mode(mode) end
+
local function key(mode)
assert(key_mode(mode))
return mode == '@' and '.' or mode:sub(2, -1)
@@ -60,9 +63,10 @@ local function conv_path(path)
local keys = {}
repeat
+ assert(mode ~= '&')
local comp = path[1]
- if comp == '#' or key_mode(comp) then
+ if contains({'#', '&'}, comp) or key_mode(comp) then
assert(not mode)
mode = comp
elseif not mode then
@@ -83,7 +87,7 @@ local function conv_path(path)
table.remove(path, 1)
until #path == 0
- return res, mode, keys
+ return res, mode, mode == '&' and {} or keys
end
@@ -104,13 +108,18 @@ function backend:get(path, top)
if existence or not top then top = aug_top(path) end
local tpe = top and top.type
- local leaf = tpe ~= 'table' and not mode
+ local tbl = tpe == 'table'
+ local leaf = not tbl and not mode
+ if mode == '&' then
+ assert(not tbl)
+ leaf = true
+ end
local matches = self.aug:match(apath..(not leaf and not mode and '/*' or ''))
- if #matches == 0 and not mode then return end
+ if #matches == 0 and not tbl_mode(mode) then return end
- if mode and #path > 1 and not self:get(
+ if tbl_mode(mode) and #path > 1 and not self:get(
array_without_last(array_without_last(path)), true
) then
return
@@ -143,7 +152,7 @@ function backend:get(path, top)
if not mode then
name = basename(child)
name = tonumber(name) or name
- if util.contains(keys, name) then name = nil end
+ if contains(keys, name) then name = nil end
elseif mode == '#' then name = i
else
name = self.aug:get(child..(mode == '@' and '' or '/'..key(mode)))
@@ -172,7 +181,7 @@ function backend:set(mods)
local parent = array_without_last(path)
local ppath, pmode = conv_path(parent)
- if pmode then
+ if tbl_mode(pmode) then
gc[pth.join(table.unpack(array_without_last(parent)))] = false
end