recyclebin: /srv/git-recyclebin -> /srv/git/_recyclebin
[girocco.git] / toolbox / trash-project.pl
blobed5e40722b7267a97b8853d5da60f8fea83b5253
1 #!/usr/bin/perl
3 # Send a project to the trash
5 use strict;
6 use warnings;
7 use lib @basedir@;
9 use Girocco::Config;
10 use Girocco::Project;
12 sub mydie
14 print STDERR "@_\n";
15 exit(255);
18 undef(*CORE::GLOBAL::die);
19 *CORE::GLOBAL::die = \&mydie;
21 my $bin = $Girocco::Config::reporoot.'/_recyclebin';
22 mkdir $bin;
24 my $project = shift @ARGV || die "Please give project name on command line.";
26 # WARNING!
27 # Physical removal isn't actually supported. You have to do it manually.
28 # This only deletes the project from the list.
29 my $delete = 0;
30 if ($project eq '--really-delete') {
31 $delete = 1;
32 $project = shift @ARGV || die "Please give project name on command line.";
35 # WARNING!
36 # Don't use this option while jobd is running. You run the risk of destroying data.
37 my $keep_forks = 0;
38 if ($project eq '--keep-forks') {
39 $keep_forks = 1;
40 $project = shift @ARGV || die "Please give project name on command line.";
43 my $p = Girocco::Project->load($project) || die "Project '$project' not found!";
45 if ($keep_forks) {
46 # Run GC on that repository so that objects don't get lost within forks
47 my $reporoot = $Girocco::Config::reporoot;
48 my $basedir = $Girocco::Config::basedir;
49 print "We have to run GC on the repo so that the forks don't lose data. Hang on...\n";
50 system($Girocco::Config::git_bin, "--git-dir=$reporoot/$project.git", 'config',
51 '--unset', 'gitweb.lastgc');
52 $ENV{'show_progress'} = 1;
53 system("$basedir/jobd/gc.sh", $project);
54 } else {
55 die "Complicated situation: project still has forks. Please deal with it manually."
56 if (-d "$Girocco::Config::reporoot/$project/");
59 if (!$delete) {
60 use POSIX qw(strftime);
61 die "Already have a deleted version of the project. You need to make a decision now."
62 if (-d "$bin/$project.git");
64 if ($project =~ m!/!) {
65 my $parent = $project; $parent =~ s{^(.+)/.*$}{$1};
66 system('mkdir', '-p', "$bin/$parent") == 0 or
67 die "Problem creating directory hierarchy in recycle bin: $!";
70 rename $p->{'path'}, "$bin/$project.git" || die "Problem moving project data: $!";
71 my ($S,$M,$H,$d,$m,$y) = gmtime(time());
72 my $recycletime = strftime("%Y-%m-%dT%H:%M:%SZ", $S, $M, $H, $d, $m, $y, -1, -1, -1);
73 system($Girocco::Config::git_bin, "--git-dir=$bin/$project.git", 'config',
74 'girocco.recycletime', $recycletime);
76 $p->delete();
77 print "Project '$project' removed from $Girocco::Config::name".
78 ($delete ? '' : ", backup in $bin/$project.git") .".\n";