summaryrefslogtreecommitdiffstats
path: root/acf2/persistence
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2013-11-15 16:48:52 +0200
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2013-11-15 16:49:09 +0200
commit14ab26132162b248509b9c97457d9f3144960cc0 (patch)
treec6535e41c6e7a3c78fd0a987adcd4e4e1e07838e /acf2/persistence
parent93654cf83d52cd1f48a66c4a4eb0cb7b9d781add (diff)
downloadacf2-14ab26132162b248509b9c97457d9f3144960cc0.tar.bz2
acf2-14ab26132162b248509b9c97457d9f3144960cc0.tar.xz
augeas backend: remove some race conditions in set method
Diffstat (limited to 'acf2/persistence')
-rw-r--r--acf2/persistence/backends/augeas.lua21
1 files changed, 17 insertions, 4 deletions
diff --git a/acf2/persistence/backends/augeas.lua b/acf2/persistence/backends/augeas.lua
index f883409..fbe993e 100644
--- a/acf2/persistence/backends/augeas.lua
+++ b/acf2/persistence/backends/augeas.lua
@@ -46,6 +46,11 @@ local function key(mode)
return mode == '@' and '.' or mode:sub(2, -1)
end
+local function append_key_pred(path, mode, value)
+ return append_pred(path, key(mode).." = '"..value.."'")
+end
+
+
local function conv_path(path)
local res = '/files'
if #path == 0 then return res, nil, {} end
@@ -69,7 +74,7 @@ local function conv_path(path)
res = append_pred(res, comp)
else
assert(type(comp) == 'string' and comp:match('^[%w _-]+$'))
- res = append_pred(res, key(mode).." = '"..comp.."'")
+ res = append_key_pred(res, mode, comp)
table.insert(keys, key(mode))
end
mode = nil
@@ -186,10 +191,18 @@ function backend:set(mods)
if count > 0 and not new then return apath, keys end
if key_mode(pmode) then
- ppath = insert(parent, true)
+ local cpath = pmode == '@' and append_key_pred(
+ ppath, '@', ''
+ ) or append_pred(ppath, 'count('..key(pmode)..') = 0')
+
+ count = #self.aug:match(cpath)
+ assert(count < 2)
+ if count == 0 then cpath = insert(parent, true) end
+
local key = key(pmode)
- self.aug:set(ppath..'/'..key, name)
- return append_pred(ppath, key), keys
+ self.aug:set(cpath..'/'..key, name)
+
+ return append_key_pred(ppath, pmode, name), keys
end
if #matches == 0 then