[vhffs-dev] [1422] full rewrite of cvs robots

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


Revision: 1422
Author:   gradator
Date:     2009-05-30 01:01:46 +0200 (Sat, 30 May 2009)

Log Message:
-----------
full rewrite of cvs robots

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Robots/Cvs.pm
    trunk/vhffs-robots/src/cvs_create.pl
    trunk/vhffs-robots/src/cvs_delete.pl
    trunk/vhffs-robots/src/cvs_fixperms.pl


Modified: trunk/vhffs-api/src/Vhffs/Robots/Cvs.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Cvs.pm	2009-05-29 21:59:13 UTC (rev 1421)
+++ trunk/vhffs-api/src/Vhffs/Robots/Cvs.pm	2009-05-29 23:01:46 UTC (rev 1422)
@@ -41,71 +41,56 @@
 sub create_cvs
 {
 	my $cvs = shift;
+	return -1 unless defined $cvs;
+	return -1 if $cvs->get_status != Vhffs::Constants::WAITING_FOR_CREATION;
 
-    return unless(defined($cvs));
+	my $dir = $cvs->get_dir;
 
-	if( create_repository( $cvs ) > 0 )
-	{
-		$cvs->set_status( Vhffs::Constants::ACTIVATED );
-		$cvs->commit;
-		$cvs->add_history("Cvsroot now created !" );
+	if( -e $dir ) {
+		$cvs->set_status( Vhffs::Constants::CREATING_ERROR );
+		$cvs->commit();
+		$cvs->add_history('Error, directory of this cvs repository already exists! Administrators must fix the problem.');
+		return -1;
 	}
-	else
-	{
-		$cvs->add_history("Cvsroot NOT created, bots encounters errors !" );
+
+	Vhffs::Functions::create_dir( $dir );
+	Vhffs::Functions::chmod_recur( $dir , 0664 , 02775 );
+	Vhffs::Functions::change_owner_recur( $dir , $cvs->get_owner_uid , $cvs->get_owner_gid );
+	$cvs->add_history('Ok, robots find the empty directory and will create cvs repository');
+
+	system('cvs -d '.$dir.' init');
+
+	unless( -d $dir.'/CVSROOT' ) {
+		$cvs->set_status( Vhffs::Constants::CREATING_ERROR );
+		$cvs->commit();
+		$cvs->add_history('Error, nothing was created after calling the cvs binary, something is wrong.');
+		return -1;
 	}
-}
 
+	Vhffs::Functions::chmod_recur( $dir , 0664 , 02775 );
+	Vhffs::Functions::change_owner_recur( $dir , $cvs->get_owner_uid , $cvs->get_owner_gid );
 
-sub delete_cvs
-{
-	my $cvs = shift;
-    return unless(defined ($cvs));
-	my $cvsroot = $cvs->get_cvsroot;
-	my $vhffs = $cvs->{'main'};
+	$cvs->add_history('The Robots created the subversion repository');
+	$cvs->set_status( Vhffs::Constants::ACTIVATED );
+	$cvs->commit;
 
-	my $dir = $cvs->get_dir;
-	my $cmd = "rm -rf $dir";
-	system( $cmd );
-	$cvs->delete;
+	return 0;
 }
 
 
-
-sub create_repository
+sub delete_cvs
 {
 	my $cvs = shift;
-    return unless(defined $cvs);
-	my $cvsroot = $cvs->get_cvsroot;
-	my $vhffs = $cvs->{'main'};
+	return -1 unless defined $cvs;
 
-	my $datadir = $vhffs->get_config->get_datadir;
-	
 	my $dir = $cvs->get_dir;
-	return -1 if( $dir =~ /\./ );
+	system('rm -rf '.$dir.' 2>/dev/null');
 
-	Vhffs::Functions::create_dir( $dir ) if( ! -d $dir );
+	# TODO: is it a good idea here ?
+	$cvs->delete;
 
-	if( -x "/usr/bin/cvs" )
-	{
-		my $command = '/usr/bin/cvs -d '.$dir.' init';
-		system( $command );
-
-		if( Vhffs::Functions::change_owner_recur( $dir , $cvs->get_owner_uid , $cvs->get_owner_gid ) < 0 )
-		{
-			return -2;
-		}
-		else
-		{
-			return 1;
-		}
-			
-	}
-	else
-	{
-		return -1;
-	}
+	return 0;
 }
 
-1;
 
+1;

Modified: trunk/vhffs-robots/src/cvs_create.pl
===================================================================
--- trunk/vhffs-robots/src/cvs_create.pl	2009-05-29 21:59:13 UTC (rev 1421)
+++ trunk/vhffs-robots/src/cvs_create.pl	2009-05-29 23:01:46 UTC (rev 1422)
@@ -41,23 +41,21 @@
 
 my $vhffs = init Vhffs::Main;
 
-Vhffs::Robots::lock( $vhffs , "cvs" );
+Vhffs::Robots::lock( $vhffs , 'cvs' );
 
 my $cvs = Vhffs::Services::Cvs::getall( $vhffs , Vhffs::Constants::WAITING_FOR_CREATION , undef , undef  );
-my $c;
-
-foreach $c ( @{$cvs} )
+foreach my $c ( @{$cvs} )
 {
-		if( Vhffs::Robots::Cvs::create_cvs( $c ) > 0 )
-		{
-			Vhffs::Robots::vhffs_log( sprintf( "CVS: repository %s is created" , $c->get_cvsroot ) , $vhffs);
-		}
-		else
-		{
-			Vhffs::Robots::vhffs_log( sprintf( "CVS: cannot create %s CVS repository" , $c->get_cvsroot ) , $vhffs);
-		}
+	if( Vhffs::Robots::Cvs::create_cvs( $c ) != 0 )
+	{
+		Vhffs::Robots::vhffs_log( sprintf( 'CVS: repository %s is created' , $c->get_cvsroot ) , $vhffs);
+	}
+	else
+	{
+		Vhffs::Robots::vhffs_log( sprintf( 'CVS: cannot create %s CVS repository' , $c->get_cvsroot ) , $vhffs);
+	}
 }
 
-Vhffs::Robots::unlock( $vhffs , "cvs" );
+Vhffs::Robots::unlock( $vhffs , 'cvs' );
 
 exit 0;

Modified: trunk/vhffs-robots/src/cvs_delete.pl
===================================================================
--- trunk/vhffs-robots/src/cvs_delete.pl	2009-05-29 21:59:13 UTC (rev 1421)
+++ trunk/vhffs-robots/src/cvs_delete.pl	2009-05-29 23:01:46 UTC (rev 1422)
@@ -42,27 +42,25 @@
 
 my $vhffs = init Vhffs::Main;
 
-Vhffs::Robots::lock( $vhffs , "cvs" );
+Vhffs::Robots::lock( $vhffs , 'cvs' );
 
-my $lol = Vhffs::Services::Cvs::getall( $vhffs , Vhffs::Constants::TO_DELETE );
-my $cvs;
-
-foreach $cvs ( @{$lol} )
+my $repos = Vhffs::Services::Cvs::getall( $vhffs , Vhffs::Constants::TO_DELETE );
+foreach my $cvs ( @{$repos} )
 {
-    if( Vhffs::Robots::Cvs::delete_cvs( $cvs ) > 0 ) {
-        Vhffs::Robots::vhffs_log( sprintf( "Delete files from %s", $cvs->get_cvsroot ), $vhffs);
-    } else {
-        Vhffs::Robots::vhffs_log( sprintf( "Cannot delete files from %s", $cvs->get_cvsroot ), $vhffs);
-    }
+	if( Vhffs::Robots::Cvs::delete_cvs( $cvs ) != 0 ) {
+		Vhffs::Robots::vhffs_log( sprintf( 'Cannot delete files from %s', $cvs->get_cvsroot ), $vhffs);
+	} else {
+		Vhffs::Robots::vhffs_log( sprintf( 'Delete files from %s', $cvs->get_cvsroot ), $vhffs);
+	}
 
-    if( $cvs->delete > 0 ) {
-        Vhffs::Robots::vhffs_log( sprintf( "Delete CVS object %s", $cvs->get_cvsroot ), $vhffs);
-    } else {
-        Vhffs::Robots::vhffs_log( sprintf( "Cannot delete CVS object %s", $cvs->get_cvsroot ), $vhffs);
-    }
+	if( $cvs->delete < 0 ) {
+		Vhffs::Robots::vhffs_log( sprintf( 'Cannot delete CVS object %s', $cvs->get_cvsroot ), $vhffs);
+	} else {
+		Vhffs::Robots::vhffs_log( sprintf( 'Delete CVS object %s', $cvs->get_cvsroot ), $vhffs);
+	}
 }
 
 
-Vhffs::Robots::unlock( $vhffs , "cvs" );
+Vhffs::Robots::unlock( $vhffs , 'cvs' );
 
 exit 0;

Modified: trunk/vhffs-robots/src/cvs_fixperms.pl
===================================================================
--- trunk/vhffs-robots/src/cvs_fixperms.pl	2009-05-29 21:59:13 UTC (rev 1421)
+++ trunk/vhffs-robots/src/cvs_fixperms.pl	2009-05-29 23:01:46 UTC (rev 1422)
@@ -49,63 +49,47 @@
 
 my $vhffs = init Vhffs::Main;
 
-Vhffs::Robots::lock( $vhffs , "cvs" );
+Vhffs::Robots::lock( $vhffs , 'cvs' );
 
 my $cvss = Vhffs::Services::Cvs::getall( $vhffs , Vhffs::Constants::WAITING_FOR_MODIFICATION );
-my $cvs;
-my $dir;
-my $user;
-my $group;
-my $readers_file;
-my $passwd_file;
-
-
-foreach $cvs ( @{$cvss} )
+foreach my $cvs ( @{$cvss} )
 {
-	$dir = $cvs->get_dir . "/CVSROOT/" ;
-	$readers_file = $dir."/readers";
-	$passwd_file = $dir."/passwd";
-	$user = $cvs->get_user;
-	$group = $cvs->get_group;
-	#First, update uid and gid informations on files
-	if( ( defined $user ) && ( defined $group ) )
-        {
-	            Vhffs::Functions::change_owner_recur( $cvs->get_dir , $user->get_uid , $group->get_gid );
-	}
+	my $readers_file = $cvs->get_dir.'/CVSROOT/readers';
+	my $passwd_file = $cvs->get_dir.'/CVSROOT/passwd';
 
-	if( $cvs->is_public == 0 )
+	if( $cvs->is_public == 1 )
 	{
-		Vhffs::Robots::vhffs_log( sprintf( "CVS fixperm (private) for %s", $cvs->get_cvsroot ), $vhffs);
-		$cvs->add_history("CVS is now private");
-		Vhffs::Functions::chmod_recur( $cvs->get_dir , 0660 , 02770 );
+		Vhffs::Robots::vhffs_log( sprintf( 'CVS fixperm (public) for %s', $cvs->get_cvsroot ), $vhffs);
+		$cvs->add_history('CVS is now public');
+		chmod 02775 , $cvs->get_dir;
 
-		#Delete reader_file if exists
-		unlink( $readers_file ) if( -f $readers_file );
-	}
-	else
-	{
-		#Fix permissions
-		Vhffs::Robots::vhffs_log( sprintf( "CVS fixperm (public) for %s", $cvs->get_cvsroot ), $vhffs);
-		$cvs->add_history("CVS is now public");
-		Vhffs::Functions::chmod_recur( $cvs->get_dir , 0664 , 02775 );
-
-
-		#Fix readers file
-		Vhffs::Robots::vhffs_log( sprintf("CVS, put repository %s public" , $cvs->get_cvsroot), $vhffs);
-		open( FILE , ">$readers_file" ) or die( "cannot open $readers_file" );
-		print FILE "anonymous";
+		# fix readers file
+		Vhffs::Robots::vhffs_log( sprintf('CVS, put repository %s public' , $cvs->get_cvsroot), $vhffs);
+		open( FILE , '>'.$readers_file ) or die( 'cannot open '.$readers_file );
+		print FILE 'anonymous'."\n";
 		close( FILE );
+		chown $cvs->get_owner_uid , $cvs->get_owner_gid , $readers_file;
 
-		open( FILE , ">$passwd_file" ) or die( "cannot open $passwd_file" );
-		print FILE "anonymous::".$user->get_username;
+		# fix passwd file
+		open( FILE , '>'.$passwd_file ) or die( 'cannot open '.$passwd_file );
+		print FILE 'anonymous::'.$cvs->get_user->get_username."\n";
 		close( FILE );
 		chown $cvs->get_owner_uid , $cvs->get_owner_gid , $passwd_file;
-		chown $cvs->get_owner_uid , $cvs->get_owner_gid , $readers_file;
 	}
+	else
+	{
+		Vhffs::Robots::vhffs_log( sprintf( 'CVS fixperm (private) for %s', $cvs->get_cvsroot ), $vhffs);
+		$cvs->add_history('CVS is now private');
+		chmod 02770 , $cvs->get_dir;
+
+		# delete reader_file if it exists
+		unlink $readers_file if -f $readers_file;
+	}
+
 	$cvs->set_status( Vhffs::Constants::ACTIVATED );
 	$cvs->commit;
 }
 
-Vhffs::Robots::unlock( $vhffs , "cvs" );
+Vhffs::Robots::unlock( $vhffs , 'cvs' );
 
 exit 0;


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