summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMathieu Parent <math.parent@gmail.com>2009-12-13 17:54:23 (GMT)
committerMathieu Parent <math.parent@gmail.com>2009-12-13 17:54:23 (GMT)
commit59825e388ee4799b86c4519b71e092fb8a1a43b3 (patch)
tree39b6b4ff0ee5b059f6f75cc5095fd96a5fce8cca /lib
parent3c07ee6a746b3b094008edaa5774a19950c143ad (diff)
downloadperl-Kolab-59825e388ee4799b86c4519b71e092fb8a1a43b3.tar.gz
Touch configuration only when there is a change. This avoid postfix
complaining about "database X.db is older than source file X".
Diffstat (limited to 'lib')
-rw-r--r--lib/Kolab/Conf.pm41
1 files changed, 21 insertions, 20 deletions
diff --git a/lib/Kolab/Conf.pm b/lib/Kolab/Conf.pm
index 4601e6b..7274bc4 100644
--- a/lib/Kolab/Conf.pm
+++ b/lib/Kolab/Conf.pm
@@ -56,7 +56,7 @@ our @EXPORT = qw(
my %templates = ();
my %ownership = ();
my %permissions = ();
-my %templatehaschanged = ();
+my %confighaschanged = ();
my %commentchar = ();
sub fixup {
@@ -120,20 +120,8 @@ sub build {
my $perm = shift;
my $cchr = shift; # comment character
- my $oldcfg = $cfg . '.old';
my $templatedir = $Kolab::config{"templatedir"};
- my $oldmask = umask 077;
- #creating the config file is changing it
- if (! -f $cfg) {
- $templatehaschanged{$tmpl} = 1;
- Kolab::log('T', "`$cfg' creation detected", KOLAB_DEBUG );
- }
- copy($cfg, $oldcfg);
- # To avoid warnings, the backup files must be owned by root
- chown(0, 0, $oldcfg);
- umask $oldmask;
-
Kolab::log('T', "Creating new configuration file `$cfg' from template `$tmpl'", KOLAB_DEBUG );
my $template;
@@ -276,17 +264,30 @@ sub build {
$template->close;
$config->close;
- move($config->filename, $cfg) || Kolab::log('T', "Error moving configfile to $cfg, error: $!", KOLAB_ERROR );
- fixup( $cfg, $owner, $perm );
- if (-f $oldcfg) {
- my $rc = `diff -q $cfg $oldcfg`;
+ if (-f $cfg) {
+ my $cfgtemp = $config->filename;
+ my $rc = `diff -q $cfg $cfgtemp`;
chomp($rc);
if ($rc) {
- $templatehaschanged{$tmpl} = 1;
-
Kolab::log('T', "`$cfg' change detected: $rc", KOLAB_DEBUG );
+ $confighaschanged{$tmpl} = 1;
+ #making backup
+ my $cfgbackup = $cfg . '.old';
+ my $oldmask = umask 077;
+ move($cfg, $cfgbackup) || Kolab::log('T', "Error backuping configfile to $cfgbackup, error: $!", KOLAB_ERROR );
+ # To avoid warnings, the backup files must be owned by root
+ chown(0, 0, $cfgbackup);
+ umask $oldmask;
}
+ } else {
+ Kolab::log('T', "`$cfg' creation detected", KOLAB_DEBUG );
+ $confighaschanged{$tmpl} = 1;
+ }
+
+ if($confighaschanged{$tmpl}) {
+ move($config->filename, $cfg) || Kolab::log('T', "Error moving configfile to $cfg, error: $!", KOLAB_ERROR );
+ fixup( $cfg, $owner, $perm );
}
Kolab::log('T', "Finished creating configuration file `$cfg'", KOLAB_DEBUG );
@@ -621,7 +622,7 @@ sub rebuildTemplates
my %cmds = ();
foreach $key (keys %runonchange) {
- if (defined $templatehaschanged{$key})
+ if (defined $confighaschanged{$key})
{
Kolab::log('T', 'Queueing RUNONCHANGE for '.$key, KOLAB_DEBUG );
$cmds{$runonchange{$key}} = 1;