summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--aconf/model/init.lua1
-rw-r--r--aconf/model/net.lua6
-rw-r--r--aconf/model/node.lua11
-rw-r--r--aconf/model/root.lua8
-rw-r--r--aconf/model/service.lua12
-rw-r--r--aconf/modules/dnsmasq.lua4
-rw-r--r--aconf/modules/network.lua14
-rw-r--r--aconf/path.lua121
-rw-r--r--aconf/path/address/init.lua33
-rw-r--r--aconf/path/address/special.lua35
-rw-r--r--aconf/path/base.lua159
-rw-r--r--aconf/path/init.lua6
-rw-r--r--aconf/persistence/backends/augeas.lua101
-rw-r--r--aconf/persistence/backends/files.lua7
-rw-r--r--aconf/persistence/backends/json.lua8
-rw-r--r--aconf/persistence/defer.lua6
-rw-r--r--aconf/persistence/init.lua8
-rw-r--r--aconf/transaction/base.lua16
18 files changed, 338 insertions, 218 deletions
diff --git a/aconf/model/init.lua b/aconf/model/init.lua
index 01b4791..0ee876a 100644
--- a/aconf/model/init.lua
+++ b/aconf/model/init.lua
@@ -58,6 +58,7 @@ local isinstance = object.isinstance
local super = object.super
M.path = require('aconf.path')
+M.addr = require('aconf.path.address')
local store = require('aconf.persistence')
local def_store = require('aconf.persistence.defer')
diff --git a/aconf/model/net.lua b/aconf/model/net.lua
index 39ca756..48a419a 100644
--- a/aconf/model/net.lua
+++ b/aconf/model/net.lua
@@ -1,5 +1,5 @@
--[[
-Copyright (c) 2012-2014 Kaarle Ritvanen
+Copyright (c) 2012-2015 Kaarle Ritvanen
See LICENSE file for license details
--]]
@@ -15,7 +15,7 @@ local object = require('aconf.object')
local class = object.class
local super = object.super
-local pth = require('aconf.path')
+local address = require('aconf.path.address')
local update = require('aconf.util').update
@@ -26,7 +26,7 @@ local BaseIPAddress = class(String)
function BaseIPAddress:abs_mask_addr(context)
if self.mask_addr then
- return pth.join(pth.parent(context.addr), self.mask_addr)
+ return address.join(address.parent(context.addr), self.mask_addr)
end
end
diff --git a/aconf/model/node.lua b/aconf/model/node.lua
index 91f0256..21b3ec2 100644
--- a/aconf/model/node.lua
+++ b/aconf/model/node.lua
@@ -13,6 +13,7 @@ local isinstance = object.isinstance
local super = object.super
local pth = require('aconf.path')
+local address = require('aconf.path.address')
local util = require('aconf.util')
local copy = util.copy
@@ -20,7 +21,11 @@ local setdefaults = util.setdefaults
local update = util.update
-function M.null_addr(path, name) return '/null'..pth.join(path, name) end
+function M.null_addr(path, name)
+ local comps = pth.split(path)
+ table.insert(comps, pth.escape(name))
+ return address.join('/null', table.unpack(comps))
+end
M.BoundMember = class()
@@ -33,7 +38,7 @@ function M.BoundMember:init(parent, name, field)
local member = field[k]
if type(member) ~= 'function' then return member end
- local addr = field.addr or pth.escape(name)
+ local addr = field.addr or address.escape(name)
if type(addr) == 'function' then addr = addr(pmt.path, name) end
return function(self, ...)
return member(
@@ -43,7 +48,7 @@ function M.BoundMember:init(parent, name, field)
privileged=pmt.privileged,
parent=parent,
path=pth.join(pmt.path, name),
- addr=pth.to_absolute(addr, pmt.addr)
+ addr=address.to_absolute(addr, pmt.addr)
},
...
)
diff --git a/aconf/model/root.lua b/aconf/model/root.lua
index 9b05488..e8525db 100644
--- a/aconf/model/root.lua
+++ b/aconf/model/root.lua
@@ -9,6 +9,7 @@ local model = require('aconf.model.model')
local node = require('aconf.model.node')
local object = require('aconf.object')
local pth = require('aconf.path')
+local address = require('aconf.path.address')
local util = require('aconf.util')
local setdefault = util.setdefault
@@ -39,18 +40,19 @@ local order = 0
function M.topology(addr, create)
local top = _topology
if type(addr) == 'table' then addr = util.copy(addr)
- else addr = pth.split(addr) end
+ else addr = address.split(addr) end
local function defaults(top)
return util.setdefaults(top, {members={}, paths={}, referrers={}})
end
while #addr > 0 do
+ local comp = address.escape(addr[1])
if create then
- top = setdefault(defaults(top).members, addr[1], {order=order})
+ top = setdefault(defaults(top).members, comp, {order=order})
order = order + 1
else
- top = top.members[addr[1]] or top.members[pth.wildcard]
+ top = top.members[comp] or top.members['*']
if not top then return end
end
table.remove(addr, 1)
diff --git a/aconf/model/service.lua b/aconf/model/service.lua
index 6951ffc..a7c02b0 100644
--- a/aconf/model/service.lua
+++ b/aconf/model/service.lua
@@ -1,21 +1,23 @@
--[[
-Copyright (c) 2012-2014 Kaarle Ritvanen
+Copyright (c) 2012-2015 Kaarle Ritvanen
See LICENSE file for license details
--]]
local fld = require('aconf.model.field')
local new = require('aconf.model.model').new
local super = require('aconf.object').super
-local pth = require('aconf.path')
+local address = require('aconf.path.address')
local store = require('aconf.persistence')
return function(name)
local res = new()
- local addr = pth.join('/service', name)
- local eaddr = pth.join(addr, 'enabled')
+ local addr = address.join('/service', name)
+ local eaddr = address.join(addr, 'enabled')
res.enabled = fld.Boolean{addr=eaddr, required=true}
- res.status = fld.String{addr=pth.join(addr, 'status'), editable=false}
+ res.status = fld.String{
+ addr=address.join(addr, 'status'), editable=false
+ }
local function is_enabled() return store:get(eaddr) end
local enabled
diff --git a/aconf/modules/dnsmasq.lua b/aconf/modules/dnsmasq.lua
index c61a1f5..5fd831c 100644
--- a/aconf/modules/dnsmasq.lua
+++ b/aconf/modules/dnsmasq.lua
@@ -1,5 +1,5 @@
--[[
-Copyright (c) 2012-2014 Kaarle Ritvanen
+Copyright (c) 2012-2015 Kaarle Ritvanen
See LICENSE file for license details
--]]
@@ -34,7 +34,7 @@ Filter.redirect_address = M.net.IPAddress{
Filter.address = M.Model{model=Address, visible=false}
Filter.whitelist = M.Set{
type=M.net.DomainName,
- addr='server/@/#/domain/#',
+ addr='server/@/\\#/domain/#',
ui_name='Domain whitelist',
widget='inline'
}
diff --git a/aconf/modules/network.lua b/aconf/modules/network.lua
index 188ac28..82a83ef 100644
--- a/aconf/modules/network.lua
+++ b/aconf/modules/network.lua
@@ -1,5 +1,5 @@
--[[
-Copyright (c) 2012-2014 Kaarle Ritvanen
+Copyright (c) 2012-2015 Kaarle Ritvanen
See LICENSE file for license details
--]]
@@ -120,7 +120,7 @@ Interface.class = M.String{
local name = M.node.name(iface)
if name == 'lo' then return 'loopback' end
- local saddr = M.path.rawjoin('/files', iface_sys_dir, name, '.')
+ local saddr = M.addr.rawjoin('/files', iface_sys_dir, name, '.')
if not txn:get(saddr) then return 'logical' end
for _, addr in ipairs{
@@ -128,7 +128,7 @@ Interface.class = M.String{
{saddr, 'bridge'},
{'/files/proc/net/vlan', name}
} do
- if txn:get(M.path.join(table.unpack(addr))) then
+ if txn:get(M.addr.join(table.unpack(addr))) then
return 'logical'
end
end
@@ -234,10 +234,10 @@ Interface.stats = M.Collection{
type=M.Number{editable=false},
editable=false,
addr=function(path)
- return M.path.join(
- '/files/sys/class/net', M.path.name(path), 'statistics'
- )
- end,
+ return M.addr.join(
+ '/files/sys/class/net', M.path.name(path), 'statistics'
+ )
+ end,
ui_name='Statistics',
ui_member='',
widget='inline'
diff --git a/aconf/path.lua b/aconf/path.lua
deleted file mode 100644
index 85fc347..0000000
--- a/aconf/path.lua
+++ /dev/null
@@ -1,121 +0,0 @@
---[[
-Copyright (c) 2012-2015 Kaarle Ritvanen
-See LICENSE file for license details
---]]
-
-local M = {}
-
-local map = require('aconf.util').map
-
-
-M.up = {}
-M.wildcard = {}
-local special = {['..']=M.up, ['*']=M.wildcard}
-
-
-function M.is_absolute(path) return path:sub(1, 1) == '/' end
-
-
-function M.escape(comp)
- for symbol, item in pairs(special) do
- if comp == item then return symbol end
- end
- if type(comp) == 'number' then return tostring(comp) end
- local res = comp:gsub('([\\/])', '\\%1')
- return (special[res] or tonumber(res)) and '\\'..res or res
-end
-
-
-function M.rawjoin(p1, p2, ...)
- if not p2 then return p1 end
- if not M.is_absolute(p2) then p2 = '/'..p2 end
- return M.rawjoin((p1 == '/' and '' or p1)..p2, ...)
-end
-
-function M.join(parent, ...)
- local args = map(M.escape, {...})
- if parent > '' then table.insert(args, 1, parent) end
- return M.rawjoin(table.unpack(args))
-end
-
-
-function M.split(path)
- local res = {}
- local comp = ''
- local escaped
-
- local function merge(s)
- if s > '' then
- table.insert(res, not escaped and (special[s] or tonumber(s)) or s)
- end
- end
-
- while true do
- local prefix, sep, suffix = path:match('([^\\/]*)([\\/])(.*)')
- if not prefix then
- merge(comp..path)
- return res
- end
-
- comp = comp..prefix
- if sep == '\\' then
- comp = comp..suffix:sub(1, 1)
- escaped = true
- path = suffix:sub(2, -1)
- else
- merge(comp)
- comp = ''
- escaped = false
- path = suffix
- end
- end
-end
-
-
-function M.is_unique(path)
- for _, comp in ipairs(M.split(path)) do
- if comp == M.wildcard then return false end
- end
- return true
-end
-
-function M.is_subordinate(p1, p2)
- p1 = M.split(p1)
- for i, comp in ipairs(M.split(p2)) do
- if p1[i] ~= comp then return false end
- end
- return true
-end
-
-
-function M.to_absolute(path, base)
- if not M.is_absolute(path) then
- path = base..(base ~= '/' and '/' or '')..path
- end
- local comps = M.split(path)
- local i = 1
- while i <= #comps do
- if comps[i] == M.up then
- if i == 1 then error('Invalid path: '..path) end
- table.remove(comps, i - 1)
- table.remove(comps, i - 1)
- i = i - 1
- else i = i + 1 end
- end
- return M.join('/', table.unpack(comps))
-end
-
-
-function M.parent(path)
- local comps = M.split(path)
- table.remove(comps)
- return M.join('/', table.unpack(comps))
-end
-
-function M.name(path)
- local comps = M.split(path)
- return comps[#comps]
-end
-
-
-return M
diff --git a/aconf/path/address/init.lua b/aconf/path/address/init.lua
new file mode 100644
index 0000000..c62487f
--- /dev/null
+++ b/aconf/path/address/init.lua
@@ -0,0 +1,33 @@
+--[[
+Copyright (c) 2012-2015 Kaarle Ritvanen
+See LICENSE file for license details
+--]]
+
+local object = require('aconf.object')
+local class = object.class
+
+local special = require('aconf.path.address.special')
+local base = require('aconf.path.base')
+
+
+local M = {
+ special={
+ enum_keys=special.EnumKeys(),
+ value=special.Value(),
+ value_equals=special.ValueEquals
+ }
+}
+
+local _special = {['#']=M.special.enum_keys, ['&']=M.special.value}
+
+
+local AddressSyntax = class(base.Syntax)
+
+function AddressSyntax:get_special(comp)
+ if comp:sub(1, 1) == '@' then
+ return special.ValueEquals(#comp > 1 and comp:sub(2, -1) or nil)
+ end
+ return _special[comp] or object.super(self, AddressSyntax):get_special(comp)
+end
+
+return AddressSyntax():export(M)
diff --git a/aconf/path/address/special.lua b/aconf/path/address/special.lua
new file mode 100644
index 0000000..ab94fce
--- /dev/null
+++ b/aconf/path/address/special.lua
@@ -0,0 +1,35 @@
+--[[
+Copyright (c) 2012-2015 Kaarle Ritvanen
+See LICENSE file for license details
+--]]
+
+local M = {}
+
+
+local object = require('aconf.object')
+local class = object.class
+
+
+M.SpecialMode = class(require('aconf.path.base').Special)
+
+M.Value = class(M.SpecialMode)
+M.Value.symbol = '&'
+
+M.Selector = class(M.SpecialMode)
+
+M.EnumKeys = class(M.Selector)
+M.EnumKeys.symbol = '#'
+
+
+M.ValueEquals = class(M.Selector)
+
+M.ValueEquals.symbol = '@'
+
+function M.ValueEquals:init(key) self.key = key end
+
+function M.ValueEquals:tostring()
+ return object.super(self, M.ValueEquals):tostring()..(self.key or '')
+end
+
+
+return M
diff --git a/aconf/path/base.lua b/aconf/path/base.lua
new file mode 100644
index 0000000..4e2bf8f
--- /dev/null
+++ b/aconf/path/base.lua
@@ -0,0 +1,159 @@
+--[[
+Copyright (c) 2012-2015 Kaarle Ritvanen
+See LICENSE file for license details
+--]]
+
+local M = {}
+
+
+local object = require('aconf.object')
+local class = object.class
+
+local map = require('aconf.util').map
+
+
+M.Special = class()
+function M.Special:tostring() return self.symbol end
+
+local Up = class(M.Special)
+Up.symbol = '..'
+
+local Wildcard = class(M.Special)
+Wildcard.symbol = '*'
+
+
+
+M.Syntax = class()
+
+M.Syntax.up = Up()
+M.Syntax.wildcard = Wildcard()
+
+
+function M.Syntax:get_special(comp)
+ return ({['..']=M.Syntax.up, ['*']=M.Syntax.wildcard})[comp]
+end
+
+
+function M.Syntax:is_absolute(path) return path:sub(1, 1) == '/' end
+
+
+function M.Syntax:escape(comp)
+ if type(comp) == 'table' then
+ if object.isinstance(object.toinstance(comp), M.Special) then
+ return comp:tostring()
+ end
+ end
+ if type(comp) == 'number' then return tostring(comp) end
+ local res = comp:gsub('([\\/])', '\\%1')
+ return (self:get_special(res) or tonumber(res)) and '\\'..res or res
+end
+
+
+function M.Syntax:rawjoin(p1, p2, ...)
+ if not p2 then return p1 end
+ if not self:is_absolute(p2) then p2 = '/'..p2 end
+ return self:rawjoin((p1 == '/' and '' or p1)..p2, ...)
+end
+
+function M.Syntax:join(parent, ...)
+ local args = map(function(c) return self:escape(c) end, {...})
+ if parent > '' then table.insert(args, 1, parent) end
+ return self:rawjoin(table.unpack(args))
+end
+
+
+function M.Syntax:split(path)
+ local res = {}
+ local comp = ''
+ local escaped
+
+ local function merge(s)
+ if s > '' then
+ table.insert(
+ res, not escaped and (self:get_special(s) or tonumber(s)) or s
+ )
+ end
+ end
+
+ while true do
+ local prefix, sep, suffix = path:match('([^\\/]*)([\\/])(.*)')
+ if not prefix then
+ merge(comp..path)
+ return res
+ end
+
+ comp = comp..prefix
+ if sep == '\\' then
+ comp = comp..suffix:sub(1, 1)
+ escaped = true
+ path = suffix:sub(2, -1)
+ else
+ merge(comp)
+ comp = ''
+ escaped = false
+ path = suffix
+ end
+ end
+end
+
+
+function M.Syntax:is_unique(path)
+ for _, comp in ipairs(self:split(path)) do
+ if comp == self.wildcard then return false end
+ end
+ return true
+end
+
+function M.Syntax:is_subordinate(p1, p2)
+ p1 = self:split(p1)
+ for i, comp in ipairs(self:split(p2)) do
+ if p1[i] ~= comp then return false end
+ end
+ return true
+end
+
+
+function M.Syntax:to_absolute(path, base)
+ if not self:is_absolute(path) then
+ path = base..(base ~= '/' and '/' or '')..path
+ end
+ local comps = self:split(path)
+ local i = 1
+ while i <= #comps do
+ if comps[i] == self.up then
+ if i == 1 then error('Invalid path: '..path) end
+ table.remove(comps, i - 1)
+ table.remove(comps, i - 1)
+ i = i - 1
+ else i = i + 1 end
+ end
+ return self:join('/', table.unpack(comps))
+end
+
+
+function M.Syntax:parent(path)
+ local comps = self:split(path)
+ table.remove(comps)
+ return self:join('/', table.unpack(comps))
+end
+
+function M.Syntax:name(path)
+ local comps = self:split(path)
+ return comps[#comps]
+end
+
+
+function M.Syntax:export(mod)
+ if not mod then mod = {} end
+ for k, v in pairs(M.Syntax) do
+ if k ~= 'export' then
+ mod[k] = type(v) == 'function' and function(...)
+ return v(self, ...)
+ end or v
+ end
+ end
+ return mod
+end
+
+
+return M
diff --git a/aconf/path/init.lua b/aconf/path/init.lua
new file mode 100644
index 0000000..5ac9642
--- /dev/null
+++ b/aconf/path/init.lua
@@ -0,0 +1,6 @@
+--[[
+Copyright (c) 2012-2015 Kaarle Ritvanen
+See LICENSE file for license details
+--]]
+
+return require('aconf.path.base').Syntax():export()
diff --git a/aconf/persistence/backends/augeas.lua b/aconf/persistence/backends/augeas.lua
index ab73c08..aaf3ac0 100644
--- a/aconf/persistence/backends/augeas.lua
+++ b/aconf/persistence/backends/augeas.lua
@@ -1,11 +1,16 @@
--[[
-Copyright (c) 2012-2014 Kaarle Ritvanen
+Copyright (c) 2012-2015 Kaarle Ritvanen
See LICENSE file for license details
--]]
local topology = require('aconf.model.root').topology
-local class = require('aconf.object').class
-local pth = require('aconf.path')
+
+local object = require('aconf.object')
+local class = object.class
+local isinstance = object.isinstance
+
+local address = require('aconf.path.address')
+local special = require('aconf.path.address.special')
local tostr = require('aconf.persistence.util').tostring
local util = require('aconf.util')
@@ -13,9 +18,6 @@ local contains = util.contains
local copy = util.copy
-local stringy = require('stringy')
-
-
local function array_join(tbl, value)
local res = copy(tbl)
table.insert(res, value)
@@ -30,7 +32,7 @@ end
local function basename(path)
- local res, pred = path:match('^.*/([#%w._-]+)([^/]*)$')
+ local res, pred = path:match('^.*/([@#$%w._-]+)([^/]*)$')
assert(res)
assert(res ~= '#')
assert(pred == '' or pred:match('^%[.+%]$'))
@@ -39,19 +41,12 @@ end
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)
+local function append_key_pred(path, key, value)
+ return append_pred(path, key.." = '"..value.."'")
end
-local function append_key_pred(path, mode, value)
- return append_pred(path, key(mode).." = '"..value.."'")
-end
+local function key(mode) return mode.key or '.' end
+
local function conv_path(path)
@@ -63,21 +58,21 @@ local function conv_path(path)
local keys = {}
repeat
- assert(mode ~= '&')
local comp = path[1]
if mode then
- if mode == '#' then
+ if isinstance(mode, special.EnumKeys) then
assert(type(comp) == 'number')
res = append_pred(res, comp)
- else
+ elseif isinstance(mode, special.ValueEquals) then
assert(type(comp) == 'string' and comp:match('^[%w %_%-%.%#]+$'))
- res = append_key_pred(res, mode, comp)
- table.insert(keys, key(mode))
- end
+ local k = key(mode)
+ res = append_key_pred(res, k, comp)
+ table.insert(keys, k)
+ else assert(false) end
mode = nil
- elseif contains({'#', '&'}, comp) or key_mode(comp) then mode = comp
+ elseif isinstance(comp, special.SpecialMode) then mode = comp
else
res = res..'/'..comp
@@ -87,7 +82,7 @@ local function conv_path(path)
table.remove(path, 1)
until #path == 0
- return res, mode, mode == '&' and {} or keys
+ return res, mode, isinstance(mode, special.Value) and {} or keys
end
@@ -110,16 +105,17 @@ function backend:get(path, top)
local tpe = top and top.type
local tbl = tpe == 'table'
local leaf = not tbl and not mode
- if mode == '&' then
+ if isinstance(mode, special.Value) then
assert(not tbl)
leaf = true
end
local matches = self.aug:match(apath..(not leaf and not mode and '/*' or ''))
+ local is_selector = isinstance(mode, special.Selector)
- if #matches == 0 and not tbl_mode(mode) then return end
+ if #matches == 0 and not is_selector then return end
- if tbl_mode(mode) and #path > 1 and not self:get(
+ if is_selector and #path > 1 and not self:get(
array_without_last(array_without_last(path)), true
) then
return
@@ -128,7 +124,7 @@ function backend:get(path, top)
if not tpe and not mode then
if #matches > 1 then
leaf = false
- mode = '#'
+ mode = address.special.enum_keys
else
local children = self.aug:match(apath..'/*')
if #children > 0 then
@@ -153,10 +149,10 @@ function backend:get(path, top)
name = basename(child)
name = tonumber(name) or name
if contains(keys, name) then name = nil end
- elseif mode == '#' then name = i
- else
- name = self.aug:get(child..(mode == '@' and '' or '/'..key(mode)))
- end
+ elseif isinstance(mode, special.EnumKeys) then name = i
+ elseif isinstance(mode, special.ValueEquals) then
+ name = self.aug:get(child..(mode.key and '/'..mode.key or ''))
+ else assert(false) end
if name and self:get(array_join(path, name), true) then
names[name] = true
@@ -181,17 +177,17 @@ function backend:set(mods)
local parent = array_without_last(path)
local ppath, pmode = conv_path(parent)
- if tbl_mode(pmode) then
- gc[pth.join(table.unpack(array_without_last(parent)))] = false
- end
+ if isinstance(pmode, special.Selector) then
+ gc[address.join(table.unpack(array_without_last(parent)))] = false
- if pmode == '#' then
- local count = #self.aug:match(ppath)
- while count < name do
- insert(parent, true)
- count = count + 1
+ if isinstance(pmode, special.EnumKeys) then
+ local count = #self.aug:match(ppath)
+ while count < name do
+ insert(parent, true)
+ count = count + 1
+ end
+ return apath, keys
end
- return apath, keys
end
local matches = self.aug:match(apath)
@@ -199,17 +195,16 @@ function backend:set(mods)
if count > 0 and not new then return apath, keys end
- if key_mode(pmode) then
- apath = pmode == '@' and append_key_pred(
- ppath, '@', ''
- ) or append_pred(ppath, 'count('..key(pmode)..') = 0')
+ if isinstance(pmode, special.ValueEquals) then
+ apath = pmode.key and append_pred(
+ ppath, 'count('..pmode.key..') = 0'
+ ) or append_key_pred(ppath, '.', '')
matches = self.aug:match(apath)
assert(#matches < 2)
apath = matches[1] or insert(parent, true)
- local key = key(pmode)
- self.aug:set(apath..'/'..key, name)
+ self.aug:set(apath..'/'..key(pmode), name)
return apath, keys
end
@@ -244,15 +239,15 @@ function backend:set(mods)
local apath, keys = insert(path)
local is_table = type(value) == 'table'
- if not (is_table or util.contains(keys, '.')) then
+ if not (is_table or contains(keys, '.')) then
self.aug:set(apath, value ~= nil and tostr(value) or nil)
end
- util.setdefault(gc, pth.join(table.unpack(path)), true)
+ util.setdefault(gc, address.join(table.unpack(path)), true)
end
for path, _ in pairs(gc) do
- local p = pth.split(path)
+ local p = address.split(path)
while #p > 0 do
local value = self:get(p)
@@ -264,7 +259,7 @@ function backend:set(mods)
break
end
- if gc[pth.join(table.unpack(p))] ~= false then
+ if gc[address.join(table.unpack(p))] ~= false then
self.aug:rm(conv_path(p))
end
p[#p] = nil
diff --git a/aconf/persistence/backends/files.lua b/aconf/persistence/backends/files.lua
index 1c78c80..427d8bb 100644
--- a/aconf/persistence/backends/files.lua
+++ b/aconf/persistence/backends/files.lua
@@ -1,10 +1,11 @@
--[[
-Copyright (c) 2012-2014 Kaarle Ritvanen
+Copyright (c) 2012-2015 Kaarle Ritvanen
See LICENSE file for license details
--]]
local topology = require('aconf.model.root').topology
local pth = require('aconf.path')
+local address = require('aconf.path.address')
local util = require('aconf.persistence.util')
local copy = require('aconf.util').copy
@@ -29,7 +30,7 @@ local backend = require('aconf.object').class()
function backend:init() self.cache = {} end
function backend:get(path, top)
- local name = pth.join('/', table.unpack(path))
+ local name = address.join('/', table.unpack(path))
if not self.cache[name] then
local t = posix.stat(name, 'type')
@@ -69,7 +70,7 @@ end
function backend:set(mods)
for _, mod in pairs(mods) do
local path, value = table.unpack(mod)
- local name = pth.join('/', table.unpack(path))
+ local name = address.join('/', table.unpack(path))
if value == nil then
print('DEL', name)
diff --git a/aconf/persistence/backends/json.lua b/aconf/persistence/backends/json.lua
index bdf2715..5a13955 100644
--- a/aconf/persistence/backends/json.lua
+++ b/aconf/persistence/backends/json.lua
@@ -1,9 +1,9 @@
--[[
-Copyright (c) 2012-2014 Kaarle Ritvanen
+Copyright (c) 2012-2015 Kaarle Ritvanen
See LICENSE file for license details
--]]
-local pth = require('aconf.path')
+local address = require('aconf.path.address')
local Cache = require('aconf.persistence.backends.volatile')
local util = require('aconf.persistence.util')
local copy = require('aconf.util').copy
@@ -26,7 +26,7 @@ function backend:split_path(path)
local res
while #fpath > 0 do
- local fp = pth.join('/', table.unpack(fpath))
+ local fp = address.join('/', table.unpack(fpath))
if self.cache[fp] then return fp, jpath end
table.insert(jpath, 1, fpath[#fpath])
table.remove(fpath)
@@ -35,7 +35,7 @@ function backend:split_path(path)
fpath = '/'
while true do
- fpath = pth.join(fpath, jpath[1])
+ fpath = address.join(fpath, jpath[1])
table.remove(jpath, 1)
local t = posix.stat(fpath, 'type')
diff --git a/aconf/persistence/defer.lua b/aconf/persistence/defer.lua
index cfa8e8b..d7f33d8 100644
--- a/aconf/persistence/defer.lua
+++ b/aconf/persistence/defer.lua
@@ -1,12 +1,12 @@
--[[
-Copyright (c) 2012-2014 Kaarle Ritvanen
+Copyright (c) 2012-2015 Kaarle Ritvanen
See LICENSE file for license details
--]]
local object = require('aconf.object')
local super = object.super
-local pth = require('aconf.path')
+local address = require('aconf.path.address')
local DeferringCommitter = object.class(
@@ -31,7 +31,7 @@ function DeferringCommitter:_set_multiple(mods)
local path, value = table.unpack(mod)
while path > '/' do
if self.defer_paths[path] then return end
- path = pth.parent(path)
+ path = address.parent(path)
end
end
diff --git a/aconf/persistence/init.lua b/aconf/persistence/init.lua
index d95da2d..8056c16 100644
--- a/aconf/persistence/init.lua
+++ b/aconf/persistence/init.lua
@@ -1,12 +1,12 @@
--[[
-Copyright (c) 2012-2014 Kaarle Ritvanen
+Copyright (c) 2012-2015 Kaarle Ritvanen
See LICENSE file for license details
--]]
local loadmods = require('aconf.loader')
local topology = require('aconf.model.root').topology
local object = require('aconf.object')
-local pth = require('aconf.path')
+local address = require('aconf.path.address')
local util = require('aconf.util')
local contains = util.contains
@@ -34,7 +34,7 @@ function DataStore:trigger(phase, path, func)
end
function DataStore:split_path(path)
- local comps = pth.split(path)
+ local comps = address.split(path)
local backend = self.backends[comps[1]]
assert(backend)
table.remove(comps, 1)
@@ -93,7 +93,7 @@ function DataStore:_set_multiple(mods)
local tp = path
while not trigger[tp] do
trigger[tp] = true
- tp = pth.parent(tp)
+ tp = address.parent(tp)
end
local backend, comps = self:split_path(path)
diff --git a/aconf/transaction/base.lua b/aconf/transaction/base.lua
index 2bdc963..f40dcca 100644
--- a/aconf/transaction/base.lua
+++ b/aconf/transaction/base.lua
@@ -1,5 +1,5 @@
--[[
-Copyright (c) 2012-2014 Kaarle Ritvanen
+Copyright (c) 2012-2015 Kaarle Ritvanen
See LICENSE file for license details
--]]
@@ -10,7 +10,7 @@ local err = require('aconf.error')
local object = require('aconf.object')
local class = object.class
-local pth = require('aconf.path')
+local address = require('aconf.path.address')
local copy = require('aconf.util').copy
-- TODO each transaction backend (i.e. persistence manager or
@@ -130,14 +130,14 @@ function M.Transaction:_set_multiple(mods)
for _, mod in ipairs(mods) do
local path, value = table.unpack(mod)
- local ppath = pth.parent(path)
+ local ppath = address.parent(path)
local parent = self:get(ppath)
if parent == nil then
parent = {}
self:set(ppath, parent)
end
- local name = pth.name(path)
+ local name = address.name(path)
local old = self:get(path)
local is_table = type(value) == 'table'
@@ -147,7 +147,9 @@ function M.Transaction:_set_multiple(mods)
if type(old) == 'table' then
if delete then
- for _, child in ipairs(old) do self:set(pth.join(path, child)) end
+ for _, child in ipairs(old) do
+ self:set(address.join(path, child))
+ end
elseif is_table then return
elseif #old > 0 then
error('Cannot assign a primitive value to non-leaf node '..path)
@@ -186,7 +188,7 @@ function M.Transaction:commit()
local function insert_add(path)
if not handled[path] then
- local pp = pth.parent(path)
+ local pp = address.parent(path)
if self.added[pp] then insert_add(pp) end
insert(path, self.added[path])
end
@@ -197,7 +199,7 @@ function M.Transaction:commit()
local value = self.backend:get(path)
if type(value) == 'table' then
for _, child in ipairs(value) do
- local cp = pth.join(path, child)
+ local cp = address.join(path, child)
assert(self.deleted[cp])
insert_del(cp)
end