[vhffs-dev] [2031] removed system() from SCM robots |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 2031
Author: gradator
Date: 2012-02-19 23:52:48 +0100 (Sun, 19 Feb 2012)
Log Message:
-----------
removed system() from SCM robots
Modified Paths:
--------------
trunk/vhffs-api/src/Vhffs/Robots/Bazaar.pm
trunk/vhffs-api/src/Vhffs/Robots/Cvs.pm
trunk/vhffs-api/src/Vhffs/Robots/Git.pm
trunk/vhffs-api/src/Vhffs/Robots/Mercurial.pm
trunk/vhffs-api/src/Vhffs/Robots/Svn.pm
Modified: trunk/vhffs-api/src/Vhffs/Robots/Bazaar.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Bazaar.pm 2012-02-19 20:12:55 UTC (rev 2030)
+++ trunk/vhffs-api/src/Vhffs/Robots/Bazaar.pm 2012-02-19 22:52:48 UTC (rev 2031)
@@ -31,6 +31,7 @@
use strict;
use utf8;
+use Cwd;
package Vhffs::Robots::Bazaar;
@@ -58,8 +59,21 @@
Vhffs::Robots::chown_recur( $dir , $bazaar->get_owner_uid , $bazaar->get_owner_gid );
$bazaar->add_history('Ok, robots find the empty directory and will create bazaar repository');
- system('cd '.$dir.' && bzr init > /dev/null');
+ my $oldcwd = Cwd::getcwd();
+ if( chdir($dir) ) {
+ my $childpid = open( my $output, '-|', 'bzr', 'init' );
+ if($childpid) {
+ # read process output then discard
+ while(<$output>) {}
+ # wait for the child to finish
+ waitpid( $childpid, 0 );
+
+ # we don't care whether bzr succedded, we are going to check that ourself
+ }
+ }
+ chdir($oldcwd);
+
unless( -d $dir.'/.bzr' ) {
$bazaar->set_status( Vhffs::Constants::CREATING_ERROR );
$bazaar->commit();
Modified: trunk/vhffs-api/src/Vhffs/Robots/Cvs.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Cvs.pm 2012-02-19 20:12:55 UTC (rev 2030)
+++ trunk/vhffs-api/src/Vhffs/Robots/Cvs.pm 2012-02-19 22:52:48 UTC (rev 2031)
@@ -58,8 +58,17 @@
Vhffs::Robots::chown_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');
+ my $childpid = open( my $output, '-|', 'cvs', '-d', $dir, 'init' );
+ if($childpid) {
+ # read process output then discard
+ while(<$output>) {}
+ # wait for the child to finish
+ waitpid( $childpid, 0 );
+
+ # we don't care whether cvs succedded, we are going to check that ourself
+ }
+
unless( -d $dir.'/CVSROOT' ) {
$cvs->set_status( Vhffs::Constants::CREATING_ERROR );
$cvs->commit();
Modified: trunk/vhffs-api/src/Vhffs/Robots/Git.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Git.pm 2012-02-19 20:12:55 UTC (rev 2030)
+++ trunk/vhffs-api/src/Vhffs/Robots/Git.pm 2012-02-19 22:52:48 UTC (rev 2031)
@@ -32,15 +32,19 @@
use strict;
use utf8;
+use Cwd;
+use File::Path;
+use File::Basename;
+use File::Copy;
package Vhffs::Robots::Git;
use Vhffs::Services::Git;
use Vhffs::Constants;
use Vhffs::Functions;
+use Vhffs::Robots;
-sub create_repo
-{
+sub create_repo {
my $git = shift;
return -1 unless defined $git;
return -1 if $git->get_status != Vhffs::Constants::WAITING_FOR_CREATION;
@@ -59,8 +63,21 @@
Vhffs::Robots::chown_recur( $dir , $git->get_owner_uid , $git->get_owner_gid );
$git->add_history('Ok, robots find the empty directory and will create git repository');
- system('cd '.$dir.' && git init --shared=all --bare > /dev/null');
+ my $oldcwd = Cwd::getcwd();
+ if( chdir($dir) ) {
+ my $childpid = open( my $output, '-|', 'git', 'init', '--shared=all', '--bare' );
+ if($childpid) {
+ # read process output then discard
+ while(<$output>) {}
+ # wait for the child to finish
+ waitpid( $childpid, 0 );
+
+ # we don't care whether git succedded, we are going to check that ourself
+ }
+ }
+ chdir($oldcwd);
+
unless( -f $dir.'/config' ) {
$git->set_status( Vhffs::Constants::CREATING_ERROR );
$git->commit();
@@ -69,12 +86,12 @@
}
# Write a description to enhance pushed mails.
- open DESCRIPTION, '>'.$dir.'/description';
- print DESCRIPTION $git->get_reponame."\n";
- close DESCRIPTION;
+ open( my $description, '>', $dir.'/description' );
+ print $description $git->get_reponame."\n";
+ close( $description );
- Vhffs::Robots::chmod_recur( $dir , 0664 , 02775 );
- Vhffs::Robots::chown_recur( $dir , $git->get_owner_uid , $git->get_owner_gid );
+ Vhffs::Robots::chmod_recur( $dir, 0664, 02775 );
+ Vhffs::Robots::chown_recur( $dir, $git->get_owner_uid, $git->get_owner_gid );
# './hooks' directory must be owned by root to prevent abuse of servers
Vhffs::Robots::chmod_recur( $dir.'/hooks' , 0644 , 0755 );
@@ -98,9 +115,33 @@
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 );
+ File::Copy::copy( '%VHFFS_BOTS_DIR%/misc/git_post-receive', $dir.'/hooks/post-receive' );
+
+ {
+ my $childpid = open( my $output, '-|', 'git', 'config', '-f', $dir.'/config', 'hooks.mailinglist', $git->{ml_name} );
+ if($childpid) {
+ # read process output then discard
+ while(<$output>) {}
+
+ # wait for the child to finish
+ waitpid( $childpid, 0 );
+
+ # TODO: check if git config succedded
+ }
+ }
+
+ {
+ my $childpid = open( my $output, '-|', 'git', 'config', '-f', $dir.'/config', 'hooks.envelopesender', $mail_from );
+ if($childpid) {
+ # read process output then discard
+ while(<$output>) {}
+
+ # wait for the child to finish
+ waitpid( $childpid, 0 );
+
+ # TODO: check if git config succedded
+ }
+ }
}
return 0;
@@ -108,8 +149,6 @@
sub delete_repo
{
- use File::Path;
- use File::Basename;
my $git = shift;
return -1 unless defined $git;
Modified: trunk/vhffs-api/src/Vhffs/Robots/Mercurial.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Mercurial.pm 2012-02-19 20:12:55 UTC (rev 2030)
+++ trunk/vhffs-api/src/Vhffs/Robots/Mercurial.pm 2012-02-19 22:52:48 UTC (rev 2031)
@@ -31,6 +31,7 @@
use strict;
use utf8;
+use Cwd;
package Vhffs::Robots::Mercurial;
@@ -58,8 +59,21 @@
Vhffs::Robots::chown_recur( $dir , $mercurial->get_owner_uid , $mercurial->get_owner_gid );
$mercurial->add_history('Ok, robots find the empty directory and will create mercurial repository');
- system('cd '.$dir.' && hg init > /dev/null');
+ my $oldcwd = Cwd::getcwd();
+ if( chdir($dir) ) {
+ my $childpid = open( my $output, '-|', 'hg', 'init' );
+ if($childpid) {
+ # read process output then discard
+ while(<$output>) {}
+ # wait for the child to finish
+ waitpid( $childpid, 0 );
+
+ # we don't care whether hg succedded, we are going to check that ourself
+ }
+ }
+ chdir($oldcwd);
+
unless( -d $dir.'/.hg' ) {
$mercurial->set_status( Vhffs::Constants::CREATING_ERROR );
$mercurial->commit();
@@ -100,9 +114,9 @@
print $rcfileout "[web]\n";
print $rcfileout "description =\n " . $description . "\n";
+ require Vhffs::Services::MailGroup;
my $mg = new Vhffs::Services::MailGroup( $mercurial->get_main , $mercurial->get_group );
- if( defined $mg )
- {
+ if( defined $mg ) {
print $rcfileout "contact = " . $mercurial->get_group->get_groupname . '@' . $mg->{config}->{domain} . "\n";
}
print $rcfileout "\n";
Modified: trunk/vhffs-api/src/Vhffs/Robots/Svn.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Svn.pm 2012-02-19 20:12:55 UTC (rev 2030)
+++ trunk/vhffs-api/src/Vhffs/Robots/Svn.pm 2012-02-19 22:52:48 UTC (rev 2031)
@@ -134,8 +134,17 @@
Vhffs::Robots::chown_recur( $dir , $svn->get_owner_uid , $svn->get_owner_gid );
$svn->add_history('Ok, robots find the empty directory and will create svn repository');
- system('svnadmin create --fs-type fsfs '.$dir);
+ my $childpid = open( my $output, '-|', 'svnadmin', 'create', '--fs-type', 'fsfs', $dir );
+ if($childpid) {
+ # read process output then discard
+ while(<$output>) {}
+ # wait for the child to finish
+ waitpid( $childpid, 0 );
+
+ # we don't care whether svn succedded, we are going to check that ourself
+ }
+
unless( -f $dir.'/format' ) {
$svn->set_status( Vhffs::Constants::CREATING_ERROR );
$svn->commit();