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

@ -105,6 +105,61 @@ rsync.checkgauge = {
} }
--
-- Returns true for non Init and Blanket events.
--
local eventNotInitBlank =
function
(
event
)
return event.etype ~= 'Init' and event.etype ~= 'Blanket'
end
--
-- Replaces what rsync would consider filter rules by literals.
--
local replaceRsyncFilter =
function
(
path
)
if not path
then
return
end
return(
path
:gsub( '%?', '\\?' )
:gsub( '%*', '\\*' )
:gsub( '%[', '\\[' )
)
end
--
-- Mutates paths for rsync filter rules,
-- changes deletes to multi path patterns
--
local pathMutator =
function
(
etype,
path1,
path2
)
if string.byte( path1, -1 ) == 47
and etype == 'Delete'
then
return replaceRsyncFilter( path1 ) .. '***', replaceRsyncFilter( path2 )
else
return replaceRsyncFilter( path1 ), replaceRsyncFilter( path2 )
end
end
-- --
-- Spawns rsync for a list of events -- Spawns rsync for a list of events
-- --
@ -115,71 +170,20 @@ rsync.action = function
( (
inlet inlet
) )
--
-- gets all events ready for syncing -- gets all events ready for syncing
-- local elist = inlet.getEvents( eventNotInitBlank )
local elist = inlet.getEvents(
function
(
event
)
return event.etype ~= 'Init' and event.etype ~= 'Blanket'
end
)
-- -- gets the list of paths for the event list
-- Replaces what rsync would consider filter rules by literals -- deletes create multi match patterns
-- local paths = elist.getPaths( pathMutator )
local function sub
(
p
)
if not p
then
return
end
return p:
gsub( '%?', '\\?' ):
gsub( '%*', '\\*' ):
gsub( '%[', '\\[' )
end
--
-- Gets the list of paths for the event list
--
-- Deletes create multi match patterns
--
local paths = elist.getPaths(
function
(
etype,
path1,
path2
)
if string.byte( path1, -1 ) == 47
and etype == 'Delete'
then
return sub( path1 )..'***', sub( path2 )
else
return sub( path1 ), sub( path2 )
end
end
)
--
-- stores all filters by integer index -- 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
@ -205,19 +209,20 @@ rsync.action = function
do do
if path and path ~= '' if path and path ~= ''
then then
addToFilter(path) addToFilter( path )
local pp = string.match( path, '^(.*/)[^/]+/?' ) local pp = string.match( path, '^(.*/)[^/]+/?' )
while pp while pp
do do
addToFilter(pp) addToFilter( pp )
pp = string.match( pp, '^(.*/)[^/]+/?' ) pp = string.match( pp, '^(.*/)[^/]+/?' )
end end
end end
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

@ -246,15 +246,19 @@ rsyncssh.collect = function
if rc == 'ok' if rc == 'ok'
then then
log('Normal', 'Startup of "',agent.source,'" finished: ', exitcode) log('Normal', 'Startup of "', agent.source, '" finished: ', exitcode)
elseif rc == 'again' elseif rc == 'again'
then then
if settings('insist') if settings('insist')
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'
@ -293,13 +297,13 @@ rsyncssh.collect = function
if rc == 'ok' if rc == 'ok'
then then
log( 'Normal', 'Finished ',agent.etype,' ',agent.sourcePath,': ',exitcode ) log( 'Normal', 'Finished ', agent.etype,' ', agent.sourcePath, ': ', exitcode )
elseif rc == 'again' elseif rc == 'again'
then then
log( 'Normal', 'Retrying ',agent.etype,' ',agent.sourcePath,': ',exitcode ) log( 'Normal', 'Retrying ', agent.etype, ' ', agent.sourcePath, ': ', exitcode )
elseif rc == 'die' elseif rc == 'die'
then then
log( 'Normal', 'Failure ',agent.etype,' ',agent.sourcePath,': ',exitcode ) log( 'Normal', 'Failure ', agent.etype, ' ', agent.sourcePath, ': ', exitcode )
else else
log( 'Error', 'Unknown exitcode ',agent.etype,' ',agent.sourcePath,': ',exitcode ) log( 'Error', 'Unknown exitcode ',agent.etype,' ',agent.sourcePath,': ',exitcode )