mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-06-02 00:10:49 +00:00
This commit is contained in:
parent
35cabeae92
commit
43be580976
69
lsyncd.lua
69
lsyncd.lua
|
@ -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
|
||||
-- Syncs that have no name specified get an incremental default name
|
||||
--
|
||||
local function new(config)
|
||||
local o = {
|
||||
config = config,
|
||||
delays = CountArray.new(),
|
||||
delayname = {},
|
||||
source = config.source,
|
||||
processes = CountArray.new(),
|
||||
}
|
||||
return o
|
||||
end
|
||||
local nextDefaultName = 1
|
||||
|
||||
-- public interface
|
||||
return {new = new}
|
||||
end)()
|
||||
|
||||
-----
|
||||
-- Puts an action on the delay stack.
|
||||
--
|
||||
function Sync.delay(self, ename, time, path, path2)
|
||||
-----
|
||||
-- Puts an action on the delay stack.
|
||||
--
|
||||
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
|
||||
|
@ -272,7 +259,34 @@ function Sync.delay(self, ename, time, path, path2)
|
|||
delayname[path] = newd
|
||||
table.insert(delays, newd)
|
||||
end
|
||||
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
|
||||
|
@ -280,7 +294,9 @@ end
|
|||
-- 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
|
||||
|
|
Loading…
Reference in New Issue
Block a user