Skip to content

Commit

Permalink
style cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
axkibe committed Aug 29, 2016
1 parent fa30283 commit 5d2126a
Showing 1 changed file with 50 additions and 31 deletions.
81 changes: 50 additions & 31 deletions lsyncd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1558,12 +1558,15 @@ local Sync = ( function( )
exitcode
)

if rc == 'die' then
log( 'Error', 'Critical exitcode.' );
if rc == 'die'
then
log( 'Error', 'Critical exitcode.' )

terminate( -1 )
end

if rc ~= 'again' then
if rc ~= 'again'
then
-- if its active again the collecter restarted the event
removeDelay( self, delay )
log(
Expand Down Expand Up @@ -2214,23 +2217,23 @@ local Syncs = ( function( )
-- Recurvely inherits a source table to a destionation table
-- copying all keys from source.
--
-- table copy source ( cs )
-- table copy destination ( cd )
-- forced verbatim for e.g. exitcodes ( verbatim )
--
-- All entries with integer keys are inherited as additional
-- sources for non-verbatim tables
--
local function inherit( cd, cs, verbatim )

local function inherit(
cd, -- table copy destination
cs, -- table copy source
verbatim -- forced verbatim ( for e.g. 'exitcodes' )
)
-- First copies all entries with non-integer keys.
--
-- Tables are merged; already present keys are not
-- overwritten
--
-- For verbatim tables integer keys are treated like
-- non-integer keys
for k, v in pairs( cs ) do
for k, v in pairs( cs )
do
if
(
type( k ) ~= 'number' or
Expand All @@ -2249,12 +2252,15 @@ local Syncs = ( function( )

-- recursevely inherits all integer keyed tables
-- ( for non-verbatim tables )
if cs._verbatim ~= true then

if cs._verbatim ~= true
then
local n = nil
for k, v in ipairs( cs ) do

for k, v in ipairs( cs )
do
n = k
if type( v ) == 'table' then
if type( v ) == 'table'
then
inherit( cd, v )
else
cd[ #cd + 1 ] = v
Expand All @@ -2267,18 +2273,25 @@ local Syncs = ( function( )
--
-- Helper to inherit. Inherits one key.
--
inheritKV = function( cd, k, v )
inheritKV =
function(
cd, -- table copy destination
k, -- key
v -- value
)

-- don't merge inheritance controls
if k == '_merge' or k == '_verbatim' then
if k == '_merge' or k == '_verbatim'
then
return
end

local dtype = type( cd [ k ] )

if type( v ) == 'table' then

if dtype == 'nil' then
if type( v ) == 'table'
then
if dtype == 'nil'
then
cd[ k ] = { }
inherit( cd[ k ], v, k == 'exitcodes' )
elseif
Expand All @@ -2288,10 +2301,10 @@ local Syncs = ( function( )
inherit( cd[ k ], v, k == 'exitcodes' )
end

elseif dtype == 'nil' then
elseif dtype == 'nil'
then
cd[ k ] = v
end

end


Expand All @@ -2302,14 +2315,16 @@ local Syncs = ( function( )

-- workaround for backwards compatibility
-- FIXME: remove when dropping that
if settings ~= settingsSafe then
if settings ~= settingsSafe
then
log(
'Warn',
'settings = { ... } is deprecated.\n'..
' please use settings{ ... } (without the equal sign)'
)

for k, v in pairs( settings ) do
for k, v in pairs( settings )
do
uSettings[ k ] = v
end

Expand All @@ -2336,15 +2351,19 @@ local Syncs = ( function( )
}

-- Lets settings override these values.
for _, v in ipairs( inheritSettings ) do
if uSettings[ v ] then
for _, v in ipairs( inheritSettings )
do
if uSettings[ v ]
then
config[ v ] = uSettings[ v ]
end
end

-- Lets commandline override these values.
for _, v in ipairs( inheritSettings ) do
if clSettings[ v ] then
for _, v in ipairs( inheritSettings )
do
if clSettings[ v ]
then
config[ v ] = clSettings[ v ]
end
end
Expand All @@ -2353,11 +2372,10 @@ local Syncs = ( function( )
-- lets the userscript 'prepare' function
-- check and complete the config
--
if type( config.prepare ) == 'function' then

if type( config.prepare ) == 'function'
then
-- prepare is given a writeable copy of config
config.prepare( config, 4 )

end

if not config[ 'source' ] then
Expand All @@ -2375,7 +2393,8 @@ local Syncs = ( function( )
--
local realsrc = lsyncd.realdir( config.source )

if not realsrc then
if not realsrc
then
log(
'Error',
'Cannot access source directory: ',
Expand Down

0 comments on commit 5d2126a

Please sign in to comment.