From 39f2f3a37338163d3cbf5bb332f9bedc80282b79 Mon Sep 17 00:00:00 2001 From: Daniel Poelzleithner Date: Fri, 10 Dec 2021 15:05:30 +0100 Subject: [PATCH] Finish -onepass option to exit when all syncs ran sucessfully once --- lsyncd.c | 5 ----- lsyncd.lua | 32 +++++++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/lsyncd.c b/lsyncd.c index dddc9f1..7ca6ce8 100644 --- a/lsyncd.c +++ b/lsyncd.c @@ -91,7 +91,6 @@ struct settings settings = { .log_facility = LOG_USER, .log_level = LOG_NOTICE, .nodaemon = false, - .onepass = false, }; @@ -1631,10 +1630,6 @@ l_configure( lua_State *L ) { settings.nodaemon = true; } - else if( !strcmp( command, "onepass" ) ) - { - settings.onepass = true; - } else if( !strcmp( command, "logfile" ) ) { const char * file = luaL_checkstring( L, 2 ); diff --git a/lsyncd.lua b/lsyncd.lua index 478da3f..c123e09 100644 --- a/lsyncd.lua +++ b/lsyncd.lua @@ -2401,6 +2401,9 @@ local Sync = ( function ' = ', exitcode ) + -- sets the initDone after the first success + self.initDone = true + else -- sets the delay on wait again local alarm = self.config.delay @@ -2804,6 +2807,10 @@ local Sync = ( function timestamp, ' )' ) + if self.disabled + then + return + end if self.processes:size( ) >= self.config.maxProcesses then @@ -2992,6 +2999,8 @@ local Sync = ( function processes = CountArray.new( ), excludes = Excludes.new( ), filters = nil, + initDone = false, + disabled = false, -- functions addBlanketDelay = addBlanketDelay, @@ -4576,6 +4585,24 @@ function runner.cycle( error( 'runner.cycle() called while not running!' ) 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 -- if possibly. But only let Syncs invoke actions if @@ -5045,11 +5072,6 @@ function runner.initialize( firstTime ) lsyncd.configure( 'nodaemon' ) end - if uSettings.onepass - then - lsyncd.configure( 'onepass' ) - end - if uSettings.logfile then lsyncd.configure( 'logfile', uSettings.logfile )