mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-12-13 14:43:09 +00:00
This commit is contained in:
parent
43be580976
commit
86596fe7bb
47
lsyncd.lua
47
lsyncd.lua
@ -193,7 +193,6 @@ end)()
|
||||
-- Holds information about one observed directory inclusively subdirs.
|
||||
--
|
||||
local Sync = (function()
|
||||
|
||||
-----
|
||||
-- Syncs that have no name specified get an incremental default name
|
||||
--
|
||||
@ -261,17 +260,35 @@ local Sync = (function()
|
||||
end
|
||||
end
|
||||
|
||||
-----
|
||||
-- Return the nearest alarm for this Sync.
|
||||
--
|
||||
local function getAlarm(self)
|
||||
-- first checks if more processses could be spawned
|
||||
if self.processes:size() >= self.config.maxProcesses then
|
||||
return nil
|
||||
end
|
||||
|
||||
if self.delays[1] then
|
||||
return self.delays[1].alarm
|
||||
end
|
||||
end
|
||||
|
||||
-----
|
||||
-- Creates a new Sync
|
||||
--
|
||||
local function new(config)
|
||||
local s = {
|
||||
-- TODO document.
|
||||
config = config,
|
||||
delays = CountArray.new(),
|
||||
delayname = {},
|
||||
source = config.source,
|
||||
processes = CountArray.new(),
|
||||
|
||||
-- functions
|
||||
delay = delay,
|
||||
getAlarm = getAlarm,
|
||||
}
|
||||
-- provides a default name if needed
|
||||
if not config.name then
|
||||
@ -1003,21 +1020,27 @@ end
|
||||
--
|
||||
function lsyncd_get_alarm()
|
||||
local alarm = false
|
||||
for _, s in Syncs.iwalk() do
|
||||
-- TODO better handling of stati.
|
||||
if s.delays[1] and
|
||||
s.processes:size() < s.config.maxProcesses then
|
||||
if alarm then
|
||||
alarm = lsyncd.earlier(alarm, s.delays[1].alarm)
|
||||
|
||||
----
|
||||
-- checks if current nearest alarm or a is earlier
|
||||
--
|
||||
local function checkAlarm(a)
|
||||
if not a then
|
||||
return
|
||||
end
|
||||
if not alarm then
|
||||
alarm = a
|
||||
else
|
||||
alarm = s.delays[1].alarm
|
||||
alarm = lsyncd.earlier(alarm, a)
|
||||
end
|
||||
end
|
||||
|
||||
-- checks all syncs for their earliest alarm
|
||||
for _, s in Syncs.iwalk() do
|
||||
checkAlarm(s:getAlarm())
|
||||
end
|
||||
local sa = StatusFile.getAlarm()
|
||||
if sa then
|
||||
alarm = (alarm and lsyncd.earlier(sa, alarm)) or sa
|
||||
end
|
||||
-- checks if a statusfile write has been delayed
|
||||
checkAlarm(StatusFile.getAlarm())
|
||||
|
||||
log("Debug", "lysncd_get_alarm returns: ",alarm)
|
||||
return alarm
|
||||
|
Loading…
Reference in New Issue
Block a user