lifting some inline funcs

This commit is contained in:
Axel Kittenberger 2017-01-03 13:08:48 +01:00
parent 83c6436e84
commit 7bae036f03
2 changed files with 76 additions and 68 deletions

View File

@ -106,51 +106,44 @@ rsync.checkgauge = {
-- --
-- Spawns rsync for a list of events -- Returns true for non Init and Blanket events.
-- --
-- Exclusions are already handled by not having local eventNotInitBlank =
-- events for them.
--
rsync.action = function
(
inlet
)
--
-- gets all events ready for syncing
--
local elist = inlet.getEvents(
function function
( (
event event
) )
return event.etype ~= 'Init' and event.etype ~= 'Blanket' return event.etype ~= 'Init' and event.etype ~= 'Blanket'
end end
)
-- --
-- Replaces what rsync would consider filter rules by literals -- Replaces what rsync would consider filter rules by literals.
-- --
local function sub local replaceRsyncFilter =
function
( (
p path
) )
if not p if not path
then then
return return
end end
return p: return(
gsub( '%?', '\\?' ): path
gsub( '%*', '\\*' ): :gsub( '%?', '\\?' )
gsub( '%[', '\\[' ) :gsub( '%*', '\\*' )
:gsub( '%[', '\\[' )
)
end end
-- --
-- Gets the list of paths for the event list -- Mutates paths for rsync filter rules,
-- changes deletes to multi path patterns
-- --
-- Deletes create multi match patterns local pathMutator =
--
local paths = elist.getPaths(
function function
( (
etype, etype,
@ -160,26 +153,37 @@ rsync.action = function
if string.byte( path1, -1 ) == 47 if string.byte( path1, -1 ) == 47
and etype == 'Delete' and etype == 'Delete'
then then
return sub( path1 )..'***', sub( path2 ) return replaceRsyncFilter( path1 ) .. '***', replaceRsyncFilter( path2 )
else else
return sub( path1 ), sub( path2 ) return replaceRsyncFilter( path1 ), replaceRsyncFilter( path2 )
end end
end end
)
-- --
-- stores all filters by integer index -- Spawns rsync for a list of events
-- --
-- Exclusions are already handled by not having
-- events for them.
--
rsync.action = function
(
inlet
)
-- gets all events ready for syncing
local elist = inlet.getEvents( eventNotInitBlank )
-- gets the list of paths for the event list
-- deletes create multi match patterns
local paths = elist.getPaths( pathMutator )
-- stores all filters by integer index
local filterI = { } local filterI = { }
-- -- stores all filters with path index
-- Stores all filters with path index
--
local filterP = { } local filterP = { }
-- -- adds one path to the filter
-- Adds one path to the filter
--
local function addToFilter local function addToFilter
( (
path path
@ -218,6 +222,7 @@ rsync.action = function
end end
local filterS = table.concat( filterI, '\n' ) local filterS = table.concat( filterI, '\n' )
local filter0 = table.concat( filterI, '\000' ) local filter0 = table.concat( filterI, '\000' )
log( log(
@ -250,7 +255,6 @@ rsync.action = function
config.source, config.source,
config.target config.target
) )
end end

View File

@ -253,8 +253,12 @@ rsyncssh.collect = function
then then
log( 'Normal', 'Retrying startup of "', agent.source, '": ', exitcode ) log( 'Normal', 'Retrying startup of "', agent.source, '": ', exitcode )
else else
log( 'Error', 'Temporary or permanent failure on startup of "', log(
agent.source, '". Terminating since "insist" is not set.' ); 'Error',
'Temporary or permanent failure on startup of "',
agent.source, '". Terminating since "insist" is not set.'
)
terminate( -1 ) -- ERRNO terminate( -1 ) -- ERRNO
end end
elseif rc == 'die' elseif rc == 'die'