[vhffs-dev] [1417] full rewrite of git robots, fixed all permissions bugs ( git init --shared=all , chmod , chown , ...

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


Revision: 1417
Author:   gradator
Date:     2009-05-28 20:22:30 +0200 (Thu, 28 May 2009)

Log Message:
-----------
full rewrite of git robots, fixed all permissions bugs ( git init --shared=all , chmod , chown , ... )

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Robots/Git.pm
    trunk/vhffs-robots/src/git_create.pl
    trunk/vhffs-robots/src/git_delete.pl
    trunk/vhffs-robots/src/git_public.pl


Modified: trunk/vhffs-api/src/Vhffs/Robots/Git.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Git.pm	2009-05-28 14:26:51 UTC (rev 1416)
+++ trunk/vhffs-api/src/Vhffs/Robots/Git.pm	2009-05-28 18:22:30 UTC (rev 1417)
@@ -41,97 +41,84 @@
 
 sub create_repo
 {
-	my( $main , $git ) = @_;
+	my $git = shift;
+	return -1 unless defined $git;
+	return -1 if $git->get_status != Vhffs::Constants::WAITING_FOR_CREATION;
 
+	my $dir = $git->get_dir;
 
-	my $dir;
-	my $dir2;
-	my $apache_file;
-	my $user_file;
+	if( -e $dir ) {
+		$git->set_status( Vhffs::Constants::CREATING_ERROR );
+		$git->commit();
+		$git->add_history('Error, directory of this git repository already exists! Administrators must fix the problem.');
+		return -1;
+	}
 
-	if( defined $git ) 
-	{
-	    $dir = $git->get_dir;
-	    
-	    if( $git->get_status == Vhffs::Constants::WAITING_FOR_CREATION )
-	    {
-    		my $ok = 1;
-		
-	    	if( ! -e $dir ) {
-		        Vhffs::Functions::create_dir( $dir ) if( ! -d $dir );
-		        $git->add_history("Ok, robots find the empty directory and will create git repository");
-    			system("cd $dir && git --bare init > /dev/null");
+	Vhffs::Functions::create_dir( $dir );
+	Vhffs::Functions::chmod_recur( $dir , 0664 , 02775 );
+	Vhffs::Functions::change_owner_recur( $dir , $git->get_owner_uid , $git->get_owner_gid );
+	$git->add_history('Ok, robots find the empty directory and will create git repository');
 
-                # Write a description to enhance push mails.
-                open DESCRIPTION, ">$dir/description";
-                print DESCRIPTION $git->get_reponame."\n";
-                close DESCRIPTION;
+	system('cd '.$dir.' && git init --shared=all --bare > /dev/null');
 
-	    		Vhffs::Functions::chmod_recur( $dir , 0664 , 02775 );
-		        Vhffs::Functions::change_owner_recur( $dir , $git->get_owner_uid , $git->get_owner_gid );
+	unless( -f $dir.'/config' ) {
+		$git->set_status( Vhffs::Constants::CREATING_ERROR );
+		$git->commit();
+		$git->add_history('Error, nothing was created after calling the git binary, something is wrong.');
+		return -1;
+	}
 
-			# .'/hooks' directory must be owned by root to prevent abuse of servers
-	    		Vhffs::Functions::chmod_recur( $dir.'/hooks' , 0644 , 0755 );
-		        Vhffs::Functions::change_owner_recur( $dir.'/hooks' , 0 , 0 );
+	# Write a description to enhance pushed mails.
+	open DESCRIPTION, '>'.$dir.'/description';
+	print DESCRIPTION $git->get_reponame."\n";
+	close DESCRIPTION;
 
-    			$git->add_history("The Robots created the git repository");
-                } else {
-	    		$ok = 0;
-			#TODO support syslog
-			$git->set_status( Vhffs::Constants::CREATING_ERROR );
-    			$git->commit();
-	    		$git->add_history("Error, directory of this git repository already exists! Administrators must fix the problem.");
-	        }
-		if( $ok == 1 ) {
-			$git->set_status( Vhffs::Constants::ACTIVATED );
-		    
-			if( $git->commit < 0 ) {
-				$git->add_history("Cannot commit changes on the object!");
-	    	  	} else {
-		   	 	$git->add_history("Git repository is now active");
-		        }
-		} else {
-		        $git->add_history("Object is not created, problem while creating it");
-    		}
-            }
-	}
+	Vhffs::Functions::chmod_recur( $dir , 0664 , 02775 );
+	Vhffs::Functions::change_owner_recur( $dir , $git->get_owner_uid , $git->get_owner_gid );
+
+	# './hooks' directory must be owned by root to prevent abuse of servers
+	Vhffs::Functions::chmod_recur( $dir.'/hooks' , 0644 , 0755 );
+	Vhffs::Functions::change_owner_recur( $dir.'/hooks' , 0 , 0 );
+
+	$git->add_history('The Robots created the git repository');
+	$git->set_status( Vhffs::Constants::ACTIVATED );
+	$git->commit;
+
+	return 0;
 }
 
 sub change_conf {
-    my $git = shift;
-    my $dir = $git->get_dir;
-    my $mail_from = $git->get_main->get_config->get_service('git')->{notify_from};
+	my $git = shift;
+	return -1 unless defined $git;
 
-    # Always unlink since git init create a dummy post-receive
-    unlink "$dir/hooks/post-receive";
-    if($git->get_ml_name !~ /^\s*$/) {
-        if(! -e "$dir/hooks/post-receive") {
-            system("cp %VHFFS_BOTS_DIR%/misc/git_post-receive $dir/hooks/post-receive");
-        }
-        system("git-config -f $dir/config hooks.mailinglist ".$git->{ml_name});
-        system("git-config -f $dir/config hooks.envelopesender $mail_from");
-    }
+	my $dir = $git->get_dir;
+	my $mail_from = $git->get_main->get_config->get_service('git')->{notify_from};
+
+	# Always unlink since git init create a dummy post-receive
+	unlink $dir.'/hooks/post-receive';
+
+	if( $git->get_ml_name !~ /^\s*$/ ) {
+		system('cp %VHFFS_BOTS_DIR%/misc/git_post-receive '.$dir.'/hooks/post-receive' );
+		system('git-config -f '.$dir.'/config hooks.mailinglist '.$git->{ml_name} );
+		system('git-config -f '.$dir.'/config hooks.envelopesender '.$mail_from );
+	}
+
+	return 0;
 }
 
 sub delete_repo
 {
-	my $main = shift;
 	my $git = shift;
+	return -1 unless defined $git;
 
-	my $dir;
-	my $dir2;
+	my $dir = $git->get_dir;
+	system('rm -rf '.$dir.' 2>/dev/null');
 
-	if( defined $git ) {
-	    $dir = $git->get_dir;
-	    system("rm -rf $dir 2>/dev/null");
-	    $git->delete;
-    } else {
-	    return -1;
-	}
-	
-	return 1;
+	# TODO: is it a good idea here ?
+	$git->delete;
+
+	return 0;
 }
 
 
 1;
-

Modified: trunk/vhffs-robots/src/git_create.pl
===================================================================
--- trunk/vhffs-robots/src/git_create.pl	2009-05-28 14:26:51 UTC (rev 1416)
+++ trunk/vhffs-robots/src/git_create.pl	2009-05-28 18:22:30 UTC (rev 1417)
@@ -43,19 +43,18 @@
 
 my $vhffs = init Vhffs::Main;
 
-Vhffs::Robots::lock( $vhffs , "git" );
+Vhffs::Robots::lock( $vhffs , 'git' );
 
 my $repos = Vhffs::Services::Git::getall( $vhffs , Vhffs::Constants::WAITING_FOR_CREATION);
-my $git;
-foreach $git ( @{$repos} )
+foreach my $git ( @{$repos} )
 {
-	if( Vhffs::Robots::Git::create_repo( $vhffs , $git ) < 0 ) {
-    		Vhffs::Robots::vhffs_log( sprintf( "Cannot create GIT %s" , $git->get_reponame ), $vhffs);
+	if( Vhffs::Robots::Git::create_repo( $git ) != 0 ) {
+		Vhffs::Robots::vhffs_log( sprintf( 'Cannot create GIT %s' , $git->get_reponame ), $vhffs);
 	} else {
-		Vhffs::Robots::vhffs_log( sprintf( "Create GIT %s" , $git->get_reponame ), $vhffs);
+		Vhffs::Robots::vhffs_log( sprintf( 'Created GIT %s' , $git->get_reponame ), $vhffs);
 	}
 }
 
 
-Vhffs::Robots::unlock( $vhffs , "git" );
+Vhffs::Robots::unlock( $vhffs , 'git' );
 exit 0;

Modified: trunk/vhffs-robots/src/git_delete.pl
===================================================================
--- trunk/vhffs-robots/src/git_delete.pl	2009-05-28 14:26:51 UTC (rev 1416)
+++ trunk/vhffs-robots/src/git_delete.pl	2009-05-28 18:22:30 UTC (rev 1417)
@@ -43,24 +43,23 @@
 
 my $vhffs = init Vhffs::Main;
 
-Vhffs::Robots::lock( $vhffs , "git" );
+Vhffs::Robots::lock( $vhffs , 'git' );
 
-my $repos = Vhffs::Services::Git::getall( $vhffs , Vhffs::Constants::TO_DELETE);
-my $git;
-foreach $git ( @{$repos} )
+my $repos = Vhffs::Services::Git::getall( $vhffs , Vhffs::Constants::TO_DELETE );
+foreach my $git ( @{$repos} )
 {
-	if( Vhffs::Robots::Git::delete_repo( $vhffs , $git ) < 0 )	{
-		Vhffs::Robots::vhffs_log( sprintf( "Cannot delete files from GIT repository %s" , $git->get_reponame ), $vhffs);
+	if( Vhffs::Robots::Git::delete_repo( $git ) != 0 )	{
+		Vhffs::Robots::vhffs_log( sprintf( 'Cannot delete files from GIT repository %s' , $git->get_reponame ), $vhffs);
 	} else {
-		Vhffs::Robots::vhffs_log( sprintf( "Delete files from GIT repository %s" , $git->get_reponame ), $vhffs);
+		Vhffs::Robots::vhffs_log( sprintf( 'Delete files from GIT repository %s' , $git->get_reponame ), $vhffs);
 	}
 
 	if( $git->delete < 0 ) {
-		Vhffs::Robots::vhffs_log( sprintf( "Cannot delete GIT repository object %s" , $git->get_reponame ), $vhffs);
+		Vhffs::Robots::vhffs_log( sprintf( 'Cannot delete GIT repository object %s' , $git->get_reponame ), $vhffs);
 	} else {
-		Vhffs::Robots::vhffs_log( sprintf( "Delete GIT repository object %s" , $git->get_reponame ), $vhffs);
+		Vhffs::Robots::vhffs_log( sprintf( 'Delete GIT repository object %s' , $git->get_reponame ), $vhffs);
 	}
 }
 
-Vhffs::Robots::unlock( $vhffs , "git" );
+Vhffs::Robots::unlock( $vhffs , 'git' );
 exit 0;

Modified: trunk/vhffs-robots/src/git_public.pl
===================================================================
--- trunk/vhffs-robots/src/git_public.pl	2009-05-28 14:26:51 UTC (rev 1416)
+++ trunk/vhffs-robots/src/git_public.pl	2009-05-28 18:22:30 UTC (rev 1417)
@@ -43,39 +43,30 @@
 
 my $vhffs = init Vhffs::Main;
 
-Vhffs::Robots::lock( $vhffs , "git" );
+Vhffs::Robots::lock( $vhffs , 'git' );
 
 my $repos = Vhffs::Services::Git::getall( $vhffs , Vhffs::Constants::WAITING_FOR_MODIFICATION );
-my $git;
-foreach $git ( @{$repos} )
+foreach my $git ( @{$repos} )
 {
-	my $user = $git->get_user;
-	my $group = $git->get_group;
-	#First, update uid and gid informations on files
-	if( ( defined $user ) && ( defined $group ) ) {
-			Vhffs::Robots::vhffs_log( sprintf( "GIT change owner/group to %s/%s for repository %s" , $user->get_username , $group->get_groupname , $git->get_dir ) , $vhffs);
-			Vhffs::Functions::change_owner_recur( $git->get_dir , $user->get_uid , $group->get_gid );
-	}
-
 	if( $git->is_public == 1 ) {
-		Vhffs::Robots::vhffs_log( sprintf( "GIT change status %s is now public" , $git->get_dir ) , $vhffs);
-		Vhffs::Functions::chmod_recur( $git->get_dir , 0664 , 02775 );
+		chmod 02775 , $git->get_dir;
+		Vhffs::Robots::vhffs_log( sprintf( 'GIT status %s is now public' , $git->get_dir ) , $vhffs);
 	} else {
-		Vhffs::Robots::vhffs_log( sprintf( "GIT change status %s is now private" , $git->get_dir ) , $vhffs);
-		Vhffs::Functions::chmod_recur( $git->get_dir , 0660 , 02770 );
+		chmod 02770 , $git->get_dir;
+		Vhffs::Robots::vhffs_log( sprintf( 'GIT status %s is now private' , $git->get_dir ) , $vhffs);
 	}
 
 	Vhffs::Robots::Git::change_conf( $git );
 	$git->set_status( Vhffs::Constants::ACTIVATED );
 	
 	if( $git->commit < 0 ) {
-		$git->add_history( "Error while updating repository configuration");
+		$git->add_history( 'Error while updating repository configuration' );
 	} else {
-		$git->add_history( "Successfully modify repository configuration");
+		$git->add_history( 'Successfully modify repository configuration' );
 	}
 }
 
 
-Vhffs::Robots::unlock( $vhffs , "git" );
+Vhffs::Robots::unlock( $vhffs , 'git' );
 
 exit 0;


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