Finish -onepass option to exit when all syncs ran sucessfully once

This commit is contained in:
Daniel Poelzleithner 2021-12-10 15:05:30 +01:00
parent d737c03c03
commit 39f2f3a373
2 changed files with 27 additions and 10 deletions

View File

@ -91,7 +91,6 @@ struct settings settings = {
.log_facility = LOG_USER, .log_facility = LOG_USER,
.log_level = LOG_NOTICE, .log_level = LOG_NOTICE,
.nodaemon = false, .nodaemon = false,
.onepass = false,
}; };
@ -1631,10 +1630,6 @@ l_configure( lua_State *L )
{ {
settings.nodaemon = true; settings.nodaemon = true;
} }
else if( !strcmp( command, "onepass" ) )
{
settings.onepass = true;
}
else if( !strcmp( command, "logfile" ) ) else if( !strcmp( command, "logfile" ) )
{ {
const char * file = luaL_checkstring( L, 2 ); const char * file = luaL_checkstring( L, 2 );

View File

@ -2401,6 +2401,9 @@ local Sync = ( function
' = ', ' = ',
exitcode exitcode
) )
-- sets the initDone after the first success
self.initDone = true
else else
-- sets the delay on wait again -- sets the delay on wait again
local alarm = self.config.delay local alarm = self.config.delay
@ -2804,6 +2807,10 @@ local Sync = ( function
timestamp, timestamp,
' )' ' )'
) )
if self.disabled
then
return
end
if self.processes:size( ) >= self.config.maxProcesses if self.processes:size( ) >= self.config.maxProcesses
then then
@ -2992,6 +2999,8 @@ local Sync = ( function
processes = CountArray.new( ), processes = CountArray.new( ),
excludes = Excludes.new( ), excludes = Excludes.new( ),
filters = nil, filters = nil,
initDone = false,
disabled = false,
-- functions -- functions
addBlanketDelay = addBlanketDelay, addBlanketDelay = addBlanketDelay,
@ -4576,6 +4585,24 @@ function runner.cycle(
error( 'runner.cycle() called while not running!' ) error( 'runner.cycle() called while not running!' )
end end
if uSettings.onepass
then
local allDone = true
for i, s in Syncs.iwalk( )
do
if s.initDone == true
then
s.disabled = true
else
allDone = false
end
end
if allDone and processCount == 0 then
log( 'Info', 'onepass active and all syncs finished. Exiting successfully')
os.exit(0)
end
end
-- --
-- goes through all syncs and spawns more actions -- goes through all syncs and spawns more actions
-- if possibly. But only let Syncs invoke actions if -- if possibly. But only let Syncs invoke actions if
@ -5045,11 +5072,6 @@ function runner.initialize( firstTime )
lsyncd.configure( 'nodaemon' ) lsyncd.configure( 'nodaemon' )
end end
if uSettings.onepass
then
lsyncd.configure( 'onepass' )
end
if uSettings.logfile if uSettings.logfile
then then
lsyncd.configure( 'logfile', uSettings.logfile ) lsyncd.configure( 'logfile', uSettings.logfile )