steffen: server/perl-kolab/Kolab-Conf Conf.pm,1.11,1.12

cvs at intevation.de cvs at intevation.de
Mon May 31 03:27:05 CEST 2004


Author: steffen

Update of /kolabrepository/server/perl-kolab/Kolab-Conf
In directory doto:/tmp/cvs-serv30641/Kolab-Conf

Modified Files:
	Conf.pm 
Log Message:
use proper tempfiles to avoid multiple instances of kolabconf mess up

Index: Conf.pm
===================================================================
RCS file: /kolabrepository/server/perl-kolab/Kolab-Conf/Conf.pm,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- Conf.pm	24 May 2004 12:46:38 -0000	1.11
+++ Conf.pm	31 May 2004 01:27:03 -0000	1.12
@@ -1,6 +1,7 @@
 package Kolab::Conf;
 
 ##
+##  Copyright (c) 2004  Klaralvdalens Datakonsult AB
 ##  Copyright (c) 2003  Code Fusion cc
 ##
 ##    Writen by Stuart Bingë  <s.binge at codefusion.co.za>
@@ -30,6 +31,7 @@
 use warnings;
 use IO::File;
 use File::Copy;
+use File::Temp;
 use Kolab;
 use Kolab::Util;
 use Kolab::LDAP;
@@ -82,7 +84,6 @@
     my $oldcfg = $cfg . '.old';
     my $prefix = $Kolab::config{'prefix'};
 
-    my $tmpfile = $prefix . '/etc/kolab/.tmp';
     copy($cfg, $oldcfg);
     chown($Kolab::config{'kolab_uid'}, $Kolab::config{'kolab_gid'}, $oldcfg);
     #chmod(0600, $oldcfg) if ($oldcfg =~ /openldap/);
@@ -92,18 +93,24 @@
     my $template;
     if (!($template = IO::File->new($tmpl, 'r'))) {
         Kolab::log('T', "Unable to open template file `$tmpl'", KOLAB_ERROR);
-        exit(1);
+	# Error, fail gracefully
+	return;
     }
     my $config;
-    if (!($config = IO::File->new($tmpfile, 'w+', 0600 ))) {
+    if (!($config = new File::Temp( TEMPLATE => 'tmpXXXXX',
+				    DIR => $prefix.'/etc/kolab/',
+				    SUFFIX => '.kolabtmp',
+				    UNLINK => 0 ))) {
         Kolab::log('T', "Unable to open configuration file `$cfg'", KOLAB_ERROR);
         exit(1);
     }
 
+    Kolab::log('T', "Using temporary file '".$config->filename."'");
+
     my $skip = 0;
     while (<$template>) {
       if (/\@{3}if (\S+)\@{3}/) {
-	if ($Kolab::config{$1} && $Kolab::config{$1} ne "FALSE" ) {
+	if ($Kolab::config{$1} && lc($Kolab::config{$1}) ne "false" ) {
           # Keep text
 	} else {
           # Skip text
@@ -127,7 +134,7 @@
     $template->close;
     $config->close;
 
-    move($tmpfile, $cfg);
+    move($config->filename, $cfg) || Kolab::log('T', "Error moving configfile into place: $!", KOLAB_ERROR );
     fixup( $cfg, $owner, $perm );
     #chown($Kolab::config{'kolab_uid'}, $Kolab::config{'kolab_gid'}, $cfg);
     #chmod(0600, $cfg) if ($cfg =~ /openldap/);





More information about the commits mailing list