*.cgi: improve "not found that's really wierd" error
[girocco.git] / cgi / mirrorproj.cgi
blob780343dfb91cfece021f871cb1134e797aa1d565
1 #!/usr/bin/perl
2 # (c) Petr Baudis <pasky@suse.cz>
3 # GPLv2
5 use strict;
6 use warnings;
8 use lib ".";
9 use Girocco::CGI;
10 use Girocco::Config;
11 use Girocco::Project;
12 use Girocco::Util;
14 my $gcgi = Girocco::CGI->new('Project Mirroring');
15 my $cgi = $gcgi->cgi;
17 my $name = $cgi->param('name');
18 $name =~ s#\.git$## if $name; #
20 unless (defined $name) {
21 print "<p>I need the project name as an argument now.</p>\n";
22 exit;
25 if (!Girocco::Project::does_exist($name,1) && !Girocco::Project::valid_name($name)) {
26 print "<p>Invalid project name. Go away, sorcerer.</p>\n";
27 exit;
30 if (!Girocco::Project::does_exist($name,1)) {
31 print "<p>Sorry but the project $name does not exist. Now, how did you <em>get</em> here?!</p>\n";
32 exit;
35 my $proj = Girocco::Project->load($name);
36 if (!$proj) {
37 print "<p>not found project $name, that's really weird!</p>\n";
38 exit;
40 my $escname = $name;
41 $escname =~ s/[+]/%2B/g;
43 if (!$proj->{mirror}) {
44 print "<p>This project is not a mirror to be cloned.</p>\n";
45 exit;
49 $| = 1;
51 if (!$proj->{clone_logged} or $proj->{clone_failed}) {
52 # Kick off the clone since it is not running yet
53 print "<p>Initiated mirroring of ".$proj->{url}." to $Girocco::Config::name project ".
54 "<a href=\"@{[url_path($Girocco::Config::gitweburl)]}/$name.git\">$name</a>.git:</p>\n";
55 $proj->clone;
57 } elsif ($proj->{clone_in_progress}) {
58 print "<p>Mirroring of ".$proj->{url}." to $Girocco::Config::name project ".
59 "<a href=\"@{[url_path($Girocco::Config::gitweburl)]}/$name.git\">$name</a>.git in progress:</p>\n";
60 } else {
61 print "<p>Mirroring of ".$proj->{url}." to $Girocco::Config::name project ".
62 "<a href=\"@{[url_path($Girocco::Config::gitweburl)]}/$name.git\">$name</a>.git completed:</p>\n";
65 print "<pre>\n";
67 open LOG, $proj->_clonelog_path() or die "clonelog: $!";
68 tailf: for (;;) {
69 my $curpos;
70 for ($curpos = tell(LOG); <LOG>; $curpos = tell(LOG)) {
71 chomp;
72 $_ eq '@OVER@' and last tailf;
73 print "$_\n";
75 sleep 1;
76 seek(LOG, $curpos, 0); # seek to where we had been
78 close LOG;
80 print "</pre>\n";
82 $proj = Girocco::Project->load($name);
83 $proj or die "not found project $name on second load, that's _REALLY_ weird!";
85 if ($proj->{clone_failed}) {
86 print <<EOT;
87 <p><strong>Mirroring failed!</strong> Please <a
88 href="@{[url_path($Girocco::Config::webadmurl)]}/editproj.cgi?name=$escname"
89 >revisit the project settings</a>.</p>
90 EOT