diff options
Diffstat (limited to 'acf/persistence/backends/augeas.lua')
-rw-r--r-- | acf/persistence/backends/augeas.lua | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/acf/persistence/backends/augeas.lua b/acf/persistence/backends/augeas.lua index e25a568..165cf8b 100644 --- a/acf/persistence/backends/augeas.lua +++ b/acf/persistence/backends/augeas.lua @@ -24,16 +24,16 @@ backend = require('acf.object').class() function backend:init() self.aug = require('augeas').init() end -function backend:find(path, tpe) +function backend:find(path, leaf) util.map( function(comp) - return comp == strip_name(comp) and not string.match(comp, '^%.+$') + assert(comp == strip_name(comp) and not string.match(comp, '^%.+$')) end, path ) local res = aug_path(path) - if #self.aug:match(res) == 0 and #path > 1 and tpe ~= 'table' then + if #self.aug:match(res) == 0 and #path > 1 and leaf then local index = path[#path] if type(index) == 'number' then local ppath = copy(path) @@ -51,9 +51,10 @@ function backend:find(path, tpe) return res end -function backend:get(path, tpe) +function backend:get(path, top) + local tpe = top and top.type local leaf = tpe and tpe ~= 'table' - local apath, mvpath = self:find(path, tpe) + local apath, mvpath = self:find(path, leaf) local matches = self.aug:match(apath) if mvpath then @@ -90,13 +91,14 @@ function backend:set(mods) local gcpaths = {} for _, mod in ipairs(mods) do - local path, tpe, value = unpack(mod) + local path, value = unpack(mod) - self.aug:rm(aug_path(path)..(tpe and '/*' or '')) + local delete = value == nil + self.aug:rm(aug_path(path)..(delete and '' or '/*')) - local apath, mvpath, index = self:find(path, tpe) + local apath, mvpath, index = self:find(path, type(value) ~= 'table') - if tpe and mvpath then + 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)) @@ -104,10 +106,11 @@ function backend:set(mods) end end - if tpe or mvpath then self.aug:set(apath, value) + if type(value) == 'table' then value = nil end + if not delete or mvpath then self.aug:set(apath, value) elseif apath > '/' then apath = pth.parent(apath) end - if value == nil or value == '' then gcpaths[mvpath or apath] = true end + if delete or value == '' then gcpaths[mvpath or apath] = true end end local function gc(path) |