This commit is contained in:
Axel Kittenberger 2010-11-06 18:26:59 +00:00
parent 35cabeae92
commit 43be580976

View File

@ -142,7 +142,7 @@ end)()
-- Locks globals,
-- no more globals can be created
--
local function globalsLock()
local function lockGlobals()
local t = _G
local mt = getmetatable(t) or {}
mt.__index = function(t, k)
@ -193,28 +193,16 @@ end)()
-- Holds information about one observed directory inclusively subdirs.
--
local Sync = (function()
-----
-- Creates a new Sync
--
local function new(config)
local o = {
config = config,
delays = CountArray.new(),
delayname = {},
source = config.source,
processes = CountArray.new(),
}
return o
end
-- public interface
return {new = new}
end)()
-----
-- Syncs that have no name specified get an incremental default name
--
local nextDefaultName = 1
-----
-- Puts an action on the delay stack.
--
function Sync.delay(self, ename, time, path, path2)
local function delay(self, ename, time, path, path2)
log("Function", "delay(", self, ", ", ename, ", ", path, ")")
local delays = self.delays
local delayname = self.delayname
@ -229,7 +217,6 @@ function Sync.delay(self, ename, time, path, path2)
-- creates the new action
local alarm
-- TODO scope
if time and self.config.delay then
alarm = lsyncd.addtoclock(time, self.config.delay)
else
@ -274,13 +261,42 @@ function Sync.delay(self, ename, time, path, path2)
end
end
-----
-- Creates a new Sync
--
local function new(config)
local s = {
config = config,
delays = CountArray.new(),
delayname = {},
source = config.source,
processes = CountArray.new(),
delay = delay,
}
-- provides a default name if needed
if not config.name then
config.name = "Sync" .. nextDefaultName
end
-- increment default nevertheless to cause less confusion
nextDefaultName = nextDefaultName + 1
return s
end
-----
-- public interface
return {new = new}
end)()
-----
-- Syncs - a singleton
--
-- It maintains all configured directories to be synced.
--
local Syncs = (function()
-----
-- the list of all syncs
--
local list = Array.new()
-----
@ -313,6 +329,7 @@ local Syncs = (function()
-----
-- Creates a new config table and inherit all keys/values
-- from integer keyed tables
--
local uconfig = config
config = {}
inherit(config, uconfig)
@ -363,12 +380,16 @@ local Syncs = (function()
table.insert(list, s)
end
-----
-- allows to walk through all syncs
--
local function iwalk()
return ipairs(list)
end
-----
-- returns the number of syncs
--
local size = function()
return #list
end
@ -470,7 +491,7 @@ local Inotifies = (function()
if filename2 then
path2 = inotify.path..filename2
end
Sync.delay(inotify.sync, ename, time, path, path2)
inotify.sync:delay(ename, time, path, path2)
-- adds subdirs for new directories
if inotify.recurse and isdir then
if ename == "Create" then
@ -926,7 +947,7 @@ function lsyncd_initialize()
settings = settings or {}
-- From this point on, no globals may be created anymore
globalsLock()
lockGlobals()
-- TODO
if settings.statusIntervall == nil then