[vhffs-dev] [1614] Added checks for possible open errors.

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 1614
Author:   guillaumito
Date:     2010-08-09 09:58:57 +0200 (Mon, 09 Aug 2010)
Log Message:
-----------
Added checks for possible open errors.
Setting the notification mail to an empty value now reset
  the notification hook.
Added a [web] section to the rc file with project description
  and contact mail (if defined)

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Robots/Mercurial.pm

Modified: trunk/vhffs-api/src/Vhffs/Robots/Mercurial.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Mercurial.pm	2010-08-06 21:14:15 UTC (rev 1613)
+++ trunk/vhffs-api/src/Vhffs/Robots/Mercurial.pm	2010-08-09 07:58:57 UTC (rev 1614)
@@ -70,6 +70,8 @@
 	Vhffs::Functions::chmod_recur( $dir , 0664 , 02775 );
 	Vhffs::Functions::change_owner_recur( $dir , $mercurial->get_owner_uid , $mercurial->get_owner_gid );
 
+	change_conf( $mercurial );
+
 	$mercurial->add_history('The Robots created the mercurial repository');
 	$mercurial->set_status( Vhffs::Constants::ACTIVATED );
 	$mercurial->commit;
@@ -83,13 +85,36 @@
 
 	my $dir = $mercurial->get_dir;
 	my $mail_from = $mercurial->get_main->get_config->get_service('mercurial')->{notify_from};
+	my $mladdress = $mercurial->{ml_name};
 
-	if( $mercurial->get_ml_name !~ /^\s*$/ ) {
+	open( my $rcfileout , "> ", $dir . '/.hg/hgrc' );
+
+	unless (defined $rcfileout) {
+		$mercurial->add_history('An error occured while opening the repository configuration file.');
+		return -1;
+	}
+
+	my $description = $mercurial->get_description;
+	# multi line values should be indented
+	$description =~ s/(\r)?\n/\n  /g;
+
+	print $rcfileout "[web]\n";
+	print $rcfileout "description =\n  " . $description . "\n";
+	my $mg = init Vhffs::Services::MailGroup( $mercurial->get_main , $mercurial->get_group );
+	if( defined $mg )
+	{
+		print $rcfileout "contact = " . $mercurial->get_group->get_groupname . '@' . $mg->{config}->{domain} . "\n";
+	}
+	print $rcfileout "\n";
+
+	if( $mladdress !~ /^\s*$/ ) {
 		# Create the rc file
 		open( my $rcfilein , "< ", "%VHFFS_BOTS_DIR%/misc/mercurial_notify.rc" );
-		open( my $rcfileout , "> ", $dir . '/.hg/hgrc' );
 
-		my $mladdress = $mercurial->{ml_name};
+		unless (defined $rcfilein) {
+			$mercurial->add_history("Can't read the configuration template file. This is wrong, very wrong.");
+			return -1;
+		}
 		
 		while( my $line = <$rcfilein> )
 		{
@@ -99,10 +124,11 @@
 			print $rcfileout $line;
 		}
 		
-		close( $rcfileout );
 		close( $rcfilein );
 	}
 
+	close( $rcfileout );
+
 	return 0;
 }
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/