working on the new rsync config system

This commit is contained in:
Axel Kittenberger 2012-10-06 14:22:08 +02:00
parent 6f90c19196
commit a6b49c8650
5 changed files with 183 additions and 150 deletions

View File

@ -30,12 +30,14 @@ if default.direct then
error('default-direct already loaded') error('default-direct already loaded')
end end
default.direct = { local direct = { }
default.direct = direct
-- --
-- Spawns rsync for a list of events -- Spawns rsync for a list of events
-- --
action = function(inlet) direct.action = function(inlet)
-- gets all events ready for syncing -- gets all events ready for syncing
local event, event2 = inlet.getEvent() local event, event2 = inlet.getEvent()
local config = inlet.getConfig() local config = inlet.getConfig()
@ -93,12 +95,12 @@ default.direct = {
log('Warn', 'ignored an event of type "',event.etype, '"') log('Warn', 'ignored an event of type "',event.etype, '"')
inlet.discardEvent(event) inlet.discardEvent(event)
end end
end, end
----- --
-- Called when collecting a finished child process -- Called when collecting a finished child process
-- --
collect = function(agent, exitcode) direct.collect = function(agent, exitcode)
local config = agent.config local config = agent.config
if not agent.isList and agent.etype == 'Init' then if not agent.isList and agent.etype == 'Init' then
@ -125,55 +127,40 @@ default.direct = {
-- everything else is just as it is, -- everything else is just as it is,
-- there is no network to retry something. -- there is no network to retry something.
return return
end, end
----- --
-- Spawns the recursive startup sync -- Spawns the recursive startup sync
-- (currently) identical to default rsync. -- (currently) identical to default rsync.
-- --
init = default.rsync.init, direct.init = default.rsync.init
----- --
-- Checks the configuration. -- Checks the configuration.
-- --
prepare = function(config) direct.prepare = function( config, level )
if not config.target then
error('default.direct needs "target".', 4) default.rsync.prepare( config, level + 1 )
end end
if config.rsyncOps then --
error('did you mean rsyncOpts with "t"?', 4)
end
end,
-----
-- Default delay is very short. -- Default delay is very short.
-- --
delay = 1, direct.delay = 1
------ --
-- Let the core not split move events. -- Let the core not split move events.
-- --
onMove = true, direct.onMove = true
-----
-- The rsync binary called.
-- --
rsync = default.rsync.rsync,
-----
-- By default do deletes. -- By default do deletes.
-- --
delete = true, direct.delete = true
-----
-- rsync exit codes
-- --
rsyncExitCodes = default.rsyncExitCodes,
-----
-- On many system multiple disk operations just rather slow down -- On many system multiple disk operations just rather slow down
-- than speed up. -- than speed up.
maxProcesses = 1, direct.maxProcesses = 1
}

View File

@ -296,8 +296,6 @@ rsync.prepare = function(
skipTarget -- used by rsyncssh, do not check for target skipTarget -- used by rsyncssh, do not check for target
) )
level = level or 4
-- --
-- First let default.prepare test the checkgauge -- First let default.prepare test the checkgauge
-- --
@ -363,11 +361,42 @@ rsync.prepare = function(
) )
end end
--
-- computes the rsync arguments into one list -- computes the rsync arguments into one list
local rsync = config.rsync; --
local crsync = config.rsync;
rsync._computed = { true } --
local computed = rsync._computed -- everything implied by archive = true
--
local archiveFlags = {
recursive = true,
links = true,
perms = true,
times = true,
group = true,
owner = true,
devices = true,
specials = true,
hard_links = false,
acls = false,
xattrs = false,
}
--
-- if archive given the implications are filled in
--
if crsync.archive then
for k, v in pairs( archiveFlags ) do
if crsync[ k ] == nil then
crsync[ k ] = v
end
end
end
crsync._computed = { true }
local computed = crsync._computed
local computedN = 1 local computedN = 1
local shortFlags = { local shortFlags = {
@ -401,27 +430,42 @@ rsync.prepare = function(
local shorts = { '-' } local shorts = { '-' }
local shortsN = 2 local shortsN = 2
if config.rsync._extra then if crsync._extra then
for k, v in ipairs( config.rsync._extra ) do for k, v in ipairs( crsync._extra ) do
computed[ computedN ] = v computed[ computedN ] = v
computedN = computedN + 1 computedN = computedN + 1
end end
end end
for k, flag in pairs( shortFlags ) do for k, flag in pairs( shortFlags ) do
if config.rsync[k] then if crsync[ k ] then
shorts[ shortsN ] = flag shorts[ shortsN ] = flag
shortsN = shortsN + 1 shortsN = shortsN + 1
end end
end end
if config.rsync.rsh then if crsync.devices and crsync.specials then
computed[ computedN ] = '--rsh=' + config.rsync.rsh shorts[ shortsN ] = 'D'
shortsN = shortsN + 1
else
if crsync.devices then
computed[ computedN ] = '--devices'
computedN = computedN + 1 computedN = computedN + 1
end end
if config.rsync.rsync_path then if crsync.specials then
computed[ computedN ] = '--rsync-path=' + config.rsync.rsync_path computed[ computedN ] = '--specials'
computedN = computedN + 1
end
end
if crsync.rsh then
computed[ computedN ] = '--rsh=' + crsync.rsh
computedN = computedN + 1
end
if crsync.rsync_path then
computed[ computedN ] = '--rsync-path=' + crsync.rsync_path
computedN = computedN + 1 computedN = computedN + 1
end end

View File

@ -45,6 +45,8 @@ rsyncssh.checkgauge = {
-- rsyncssh users host and targetdir -- rsyncssh users host and targetdir
host = true, host = true,
targetdir = true, targetdir = true,
sshExitCodes = true,
rsyncExitCodes = true,
-- ssh settings -- ssh settings
ssh = { ssh = {
@ -254,9 +256,9 @@ end
-- --
-- checks the configuration. -- checks the configuration.
-- --
rsyncssh.prepare = function( config ) rsyncssh.prepare = function( config, level )
default.rsync.prepare( config, 5, true ) default.rsync.prepare( config, level + 1, true )
if not config.host then if not config.host then
error('default.rsyncssh needs "host" configured', 4) error('default.rsyncssh needs "host" configured', 4)

View File

@ -352,6 +352,6 @@ default.prepare = function( config, level )
return return
end end
check( config, gauge, '', level or 2 ) check( config, gauge, '', level + 1 )
end end

View File

@ -2286,7 +2286,7 @@ local Syncs = ( function( )
if type( config.prepare ) == 'function' then if type( config.prepare ) == 'function' then
-- prepare is given a writeable copy of config -- prepare is given a writeable copy of config
config.prepare( config ) config.prepare( config, 4 )
end end