summaryrefslogtreecommitdiffstats
path: root/aconf/transaction
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2015-02-22 00:08:53 +0200
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2015-02-22 01:51:30 +0200
commit1e4cb26264f67b5fe8e3e55e17d1ad785c137f24 (patch)
tree0f91b39518c6ba6ffd2f97d386ca8b0c5add3b41 /aconf/transaction
parent30ea327005ed2f45e19b2314b8caaae3c7edd894 (diff)
downloadaconf-1e4cb26264f67b5fe8e3e55e17d1ad785c137f24.tar.bz2
aconf-1e4cb26264f67b5fe8e3e55e17d1ad785c137f24.tar.xz
model: scattered lists
Diffstat (limited to 'aconf/transaction')
-rw-r--r--aconf/transaction/base.lua33
1 files changed, 31 insertions, 2 deletions
diff --git a/aconf/transaction/base.lua b/aconf/transaction/base.lua
index f40dcca..1886fd9 100644
--- a/aconf/transaction/base.lua
+++ b/aconf/transaction/base.lua
@@ -11,7 +11,7 @@ local object = require('aconf.object')
local class = object.class
local address = require('aconf.path.address')
-local copy = require('aconf.util').copy
+local util = require('aconf.util')
-- TODO each transaction backend (i.e. persistence manager or
-- transaction proper) should be implemented as a thread or have its
@@ -107,7 +107,7 @@ function M.Transaction:get(path)
if self.deleted[path] then return nil, self.mod_time[path] end
for _, tbl in ipairs{self.added, self.modified} do
if tbl[path] ~= nil then
- return copy(tbl[path]), self.mod_time[path]
+ return util.copy(tbl[path]), self.mod_time[path]
end
end
@@ -116,6 +116,35 @@ function M.Transaction:get(path)
return value, timestamp
end
+function M.Transaction:expand(path)
+ local prefix = {}
+ path = address.split(path)
+
+ while path[1] do
+ local comp = path[1]
+ table.remove(path, 1)
+
+ if comp == address.wildcard then
+ local p = address.join('/', table.unpack(prefix))
+ local res = {}
+
+ local children = self:get(p) or {}
+ table.sort(children)
+ for _, child in ipairs(children) do
+ util.extend(
+ res, self:expand(address.join(p, child, table.unpack(path)))
+ )
+ end
+
+ return res
+ end
+
+ table.insert(prefix, comp)
+ end
+
+ return {address.join('/', table.unpack(prefix))}
+end
+
function M.Transaction:_set_multiple(mods)
local function set(path, value, new)