diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2013-06-27 22:51:25 +0300 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2013-06-28 13:24:36 +0300 |
commit | c6e42f5bed1695200b789ce897a26d3f8e9c7cb2 (patch) | |
tree | 16af99f04a05fba31043d9e52ab08a930ed8c457 /acf | |
parent | 5c960909594d1978f45968f8155ab2afab381298 (diff) | |
download | aconf-c6e42f5bed1695200b789ce897a26d3f8e9c7cb2.tar.bz2 aconf-c6e42f5bed1695200b789ce897a26d3f8e9c7cb2.tar.xz |
augeas back-end: order nodes according to model topology
Diffstat (limited to 'acf')
-rw-r--r-- | acf/persistence/backends/augeas.lua | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/acf/persistence/backends/augeas.lua b/acf/persistence/backends/augeas.lua index 165cf8b..9d6b4cc 100644 --- a/acf/persistence/backends/augeas.lua +++ b/acf/persistence/backends/augeas.lua @@ -5,6 +5,7 @@ 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.util') @@ -97,12 +98,30 @@ function backend:set(mods) self.aug:rm(aug_path(path)..(delete and '' or '/*')) local apath, mvpath, index = self:find(path, type(value) ~= 'table') + local mpath = mvpath or apath + + if not delete then + if #self.aug:match(mpath) == 0 then + + local function order(path) + return topology('/augeas'..path).order + end + local ord = order(pth.join('/', unpack(path))) + + for _, sibling in ipairs(self.aug:match(pth.parent(mpath)..'/*')) do + if order(string.sub(strip_name(sibling), 7, -1)) > ord then + self.aug:insert(sibling, pth.name(mpath), true) + break + end + end + end - if not delete and mvpath then - local size = #self.aug:match(mvpath) - while size < index do - self.aug:insert(ipath(mvpath, size), pth.name(mvpath)) - size = size + 1 + if mvpath then + local size = #self.aug:match(mvpath) + while size < index do + self.aug:insert(ipath(mvpath, size), pth.name(mvpath)) + size = size + 1 + end end end @@ -110,7 +129,7 @@ function backend:set(mods) if not delete or mvpath then self.aug:set(apath, value) elseif apath > '/' then apath = pth.parent(apath) end - if delete or value == '' then gcpaths[mvpath or apath] = true end + if delete or value == '' then gcpaths[mpath] = true end end local function gc(path) |