From 31bd7bd491738d8653a9e181594969a3665aca22 Mon Sep 17 00:00:00 2001 From: Kaarle Ritvanen Date: Tue, 10 Mar 2015 21:11:19 +0200 Subject: persistence: move augeas back-end directives out of addresses --- aconf/persistence/backends/augeas.lua | 36 ++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'aconf/persistence') 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) -- cgit v1.2.3