From 786455b2871c8a81de725d5b04b824d5da16a284 Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Thu, 11 Aug 2011 20:19:30 -0700 Subject: [PATCH] Unlink .bak file if no changes to .conf. Signed-off-by: Tom Eastep --- Shorewall/Perl/Shorewall/Config.pm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Shorewall/Perl/Shorewall/Config.pm b/Shorewall/Perl/Shorewall/Config.pm index 9147cb3e7..92ff32637 100644 --- a/Shorewall/Perl/Shorewall/Config.pm +++ b/Shorewall/Perl/Shorewall/Config.pm @@ -3054,8 +3054,19 @@ EOF fatal_error "Can't rename $configfile to $configfile.bak: $!" unless rename $configfile, "$configfile.bak"; fatal_error "Can't rename $configfile.updated to $configfile: $!" unless rename "$configfile.updated", $configfile; + + if ( system( "diff -q $configfile $configfile.bak > /dev/null" ) ) { + progress_message3 "Configuration file $configfile updated - old file renamed $configfile.bak"; + } else { + if ( unlink "$configfile.bak" ) { + progress_message3 "No update required to configuration file $configfile; $configfile.bak not saved"; + } else { + warning_message "Unable to unlink $configfile.bak"; + progress_message3 "No update required to configuration file $configfile; $configfile.b"; + } - progress_message3 "Configuration file $configfile updated - old file renamed $configfile.bak"; + exit 0; + } } else { fatal_error "$fn does not exist"; }