code beautify

This commit is contained in:
Axel Kittenberger 2016-11-25 14:55:59 +01:00
parent 8367ae89a0
commit 4d2c793b01
2 changed files with 79 additions and 89 deletions

View File

@ -283,14 +283,16 @@ rsyncssh.prepare = function( config, level )
default.rsync.prepare( config, level + 1, true ) default.rsync.prepare( config, level + 1, true )
if not config.host then if not config.host
then
error( error(
'default.rsyncssh needs "host" configured', 'default.rsyncssh needs "host" configured',
level level
) )
end end
if not config.targetdir then if not config.targetdir
then
error( error(
'default.rsyncssh needs "targetdir" configured', 'default.rsyncssh needs "targetdir" configured',
level level
@ -300,44 +302,37 @@ rsyncssh.prepare = function( config, level )
-- --
-- computes the ssh options -- computes the ssh options
-- --
if config.ssh._computed then if config.ssh._computed
then
error( error(
'please do not use the internal rsync._computed parameter', 'please do not use the internal rsync._computed parameter',
level level
) )
end end
local cssh = local cssh = config.ssh;
config.ssh;
cssh._computed = cssh._computed = { }
{ }
local computed = local computed = cssh._computed
cssh._computed
local computedN = local computedN = 1
1
local rsyncc = local rsyncc = config.rsync._computed
config.rsync._computed
if cssh.identityFile then if cssh.identityFile
computed[ computedN ] = then
'-i' computed[ computedN ] = '-i'
computed[ computedN + 1 ] = computed[ computedN + 1 ] = cssh.identityFile
cssh.identityFile
computedN = computedN = computedN + 2
computedN + 2
if not config.rsync._rshIndex then if not config.rsync._rshIndex
config.rsync._rshIndex = then
#rsyncc + 1 config.rsync._rshIndex = #rsyncc + 1
rsyncc[ config.rsync._rshIndex ] = rsyncc[ config.rsync._rshIndex ] = '--rsh=ssh'
'--rsh=ssh'
end end
rsyncc[ config.rsync._rshIndex ] = rsyncc[ config.rsync._rshIndex ] =
@ -346,26 +341,21 @@ rsyncssh.prepare = function( config, level )
cssh.identityFile cssh.identityFile
end end
if cssh.options then if cssh.options
then
for k, v in pairs( cssh.options )
do
computed[ computedN ] = '-o'
computed[ computedN + 1 ] = k .. '=' .. v
for k, v in pairs( cssh.options ) do computedN = computedN + 2
computed[ computedN ] = if not config.rsync._rshIndex
'-o' then
config.rsync._rshIndex = #rsyncc + 1
computed[ computedN + 1 ] = rsyncc[ config.rsync._rshIndex ] = '--rsh=ssh'
k .. '=' .. v
computedN =
computedN + 2
if not config.rsync._rshIndex then
config.rsync._rshIndex =
#rsyncc + 1
rsyncc[ config.rsync._rshIndex ] =
'--rsh=ssh'
end end
rsyncc[ config.rsync._rshIndex ] = rsyncc[ config.rsync._rshIndex ] =
@ -382,40 +372,38 @@ rsyncssh.prepare = function( config, level )
end end
end end
if cssh.port then if cssh.port
computed[ computedN ] = then
'-p' computed[ computedN ] = '-p'
computed[ computedN + 1 ] = computed[ computedN + 1 ] = cssh.port
cssh.port
computedN = computedN = computedN + 2
computedN + 2
if not config.rsync._rshIndex then if not config.rsync._rshIndex
config.rsync._rshIndex = then
#rsyncc + 1 config.rsync._rshIndex = #rsyncc + 1
rsyncc[ config.rsync._rshIndex ] = rsyncc[ config.rsync._rshIndex ] = '--rsh=ssh'
'--rsh=ssh'
end end
rsyncc[ config.rsync._rshIndex ] = rsyncc[ config.rsync._rshIndex ] =
rsyncc[ config.rsync._rshIndex ] .. ' -p ' .. cssh.port rsyncc[ config.rsync._rshIndex ] .. ' -p ' .. cssh.port
end end
if cssh._extra then if cssh._extra
for k, v in ipairs( cssh._extra ) do then
computed[ computedN ] = for k, v in ipairs( cssh._extra )
v do
computed[ computedN ] = v
computedN = computedN = computedN + 1
computedN + 1
end end
end end
-- appends a slash to the targetdir if missing -- appends a slash to the targetdir if missing
if string.sub( config.targetdir, -1 ) ~= '/' then if string.sub( config.targetdir, -1 ) ~= '/'
then
config.targetdir = config.targetdir =
config.targetdir .. '/' config.targetdir .. '/'
end end

View File

@ -3349,16 +3349,18 @@ local UserAlarms = ( function( )
local alarms = { } local alarms = { }
-- --
-- Calls the user function at timestamp. -- Calls the user function at timestamp.
-- --
local function alarm( timestamp, func, extra ) local function alarm( timestamp, func, extra )
local idx local idx
for k, v in ipairs( alarms ) do
if timestamp < v.timestamp then for k, v in ipairs( alarms )
do
if timestamp < v.timestamp
then
idx = k idx = k
break break
end end
end end
@ -3369,12 +3371,12 @@ local UserAlarms = ( function( )
extra = extra extra = extra
} }
if idx then if idx
then
table.insert( alarms, idx, a ) table.insert( alarms, idx, a )
else else
table.insert( alarms, a ) table.insert( alarms, a )
end end
end end
@ -3382,13 +3384,12 @@ local UserAlarms = ( function( )
-- Retrieves the soonest alarm. -- Retrieves the soonest alarm.
-- --
local function getAlarm( ) local function getAlarm( )
if #alarms == 0
if #alarms == 0 then then
return false return false
else else
return alarms[1].timestamp return alarms[1].timestamp
end end
end end
@ -3415,7 +3416,6 @@ local UserAlarms = ( function( )
invoke = invoke invoke = invoke
} }
end )( ) end )( )
--============================================================================ --============================================================================
@ -3451,11 +3451,13 @@ function runner.callError( message )
-- prints backtrace -- prints backtrace
local level = 2 local level = 2
while true do
while true
do
local info = debug.getinfo( level, 'Sl' ) local info = debug.getinfo( level, 'Sl' )
if not info then if not info
then
terminate( -1 ) terminate( -1 )
end end
@ -3502,11 +3504,10 @@ end
function runner.cycle( function runner.cycle(
timestamp -- the current kernel time (in jiffies) timestamp -- the current kernel time (in jiffies)
) )
if lsyncdStatus == 'fade'
if lsyncdStatus == 'fade' then then
if processCount > 0
if processCount > 0 then then
if if
lastReportedWaiting == false or lastReportedWaiting == false or
timestamp >= lastReportedWaiting + 60 timestamp >= lastReportedWaiting + 60
@ -3523,7 +3524,6 @@ function runner.cycle(
return true return true
else else
return false return false
end end
end end
@ -3546,13 +3546,12 @@ function runner.cycle(
local ir = start local ir = start
repeat repeat
local s = Syncs.get( ir ) local s = Syncs.get( ir )
s:invokeActions( timestamp ) s:invokeActions( timestamp )
ir = ir + 1 ir = ir + 1
if ir > Syncs.size( ) then if ir > Syncs.size( )
then
ir = 1 ir = 1
end end
until ir == start until ir == start
@ -3562,7 +3561,8 @@ function runner.cycle(
UserAlarms.invoke( timestamp ) UserAlarms.invoke( timestamp )
if uSettings.statusFile then if uSettings.statusFile
then
StatusFile.write( timestamp ) StatusFile.write( timestamp )
end end
@ -4050,13 +4050,14 @@ end
-- --
-- Called by core to query the soonest alarm. -- Called by core to query the soonest alarm.
-- --
-- @return false ... no alarm, core can in untimed sleep, or -- @return false ... no alarm, core can go in untimed sleep
-- true ... immediate action -- true ... immediate action
-- times ... the alarm time (only read if number is 1) -- times ... the alarm time (only read if number is 1)
-- --
function runner.getAlarm( ) function runner.getAlarm( )
if lsyncdStatus ~= 'run' then if lsyncdStatus ~= 'run'
then
return false return false
end end
@ -4066,22 +4067,23 @@ function runner.getAlarm( )
-- Checks if 'a' is sooner than the 'alarm' up-value. -- Checks if 'a' is sooner than the 'alarm' up-value.
-- --
local function checkAlarm( a ) local function checkAlarm( a )
if a == nil
if a == nil then then
error('got nil alarm') error('got nil alarm')
end end
if alarm == true or not a then if alarm == true or not a
then
-- 'alarm' is already immediate or -- 'alarm' is already immediate or
-- a not a new alarm -- a not a new alarm
return return
end end
-- sets 'alarm' to a if a is sooner -- sets 'alarm' to a if a is sooner
if not alarm or a < alarm then if not alarm or a < alarm
then
alarm = a alarm = a
end end
end end
-- --