gluon-announce{,d}: create a new UCI cursor for each run

This commit is contained in:
Matthias Schiffer 2015-12-18 17:44:16 +01:00
parent 077dbe3c08
commit c3150d821f
2 changed files with 19 additions and 2 deletions

View File

@ -3,8 +3,11 @@
module('gluon.announce', package.seeall)
fs = require 'nixio.fs'
uci = require('luci.model.uci').cursor()
util = require 'gluon.util'
model_uci = require 'luci.model.uci'
local collect_dir
local function collect_entry(entry)
if fs.stat(entry, 'type') == 'dir' then
@ -49,3 +52,17 @@ function collect_dir(dir)
return ret
end
end
function collect(dir)
local f = collect_dir(dir)
return function ()
_M.uci = model_uci.cursor()
ret = f()
_M.uci = nil
collectgarbage()
return ret
end
end

View File

@ -12,7 +12,7 @@ nixio.chdir('/lib/gluon/announce/')
for dir in fs.glob('*.d') do
local name = dir:sub(1, -3)
memoize[name] = {
collect = announce.collect_dir(dir),
collect = announce.collect(dir),
-- tonumber will return 0 for invalid inputs
cache_time = tonumber(util.trim(fs.readfile(name .. '.cache') or ''))
}