]> git.decadent.org.uk Git - dak.git/blobdiff - tools/debianqueued-0.9/debianqueued
Clarify rm /
[dak.git] / tools / debianqueued-0.9 / debianqueued
index 258386a6c25175fd69ddcdc26d46212831911dc9..eebb91513b9aca8ac3339fa41c7d89e27185380c 100755 (executable)
@@ -4,6 +4,7 @@
 #
 # Copyright (C) 1997 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
 # Copyright (C) 2001-2007 Ryan Murray <rmurray@debian.org>
+# Copyright (C) 2008 Thomas Viehmann <tv@beamnet.de>
 #
 # This program is free software.  You can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -1065,60 +1066,53 @@ sub process_commands($) {
        foreach $cmd ( @cmds ) {
                my @word = split( /\s+/, $cmd );
                msg( "mail,log", "> @word\n" );
+        my $selecteddelayed = -1;
                next if @word < 1;
-               
+
                if ($word[0] eq "rm") {
                        foreach ( @word[1..$#word] ) {
-                               if (m,/,) {
-                                       msg( "mail,log", "$_: filename may not contain slashes\n" );
+                               my $origword = $_;
+                               if (m,^DELAYED/([0-9]+)-day/,) {
+                                       $selecteddelayed = $1;
+                    s,^DELAYED/[0-9]+-day/,,;
+                               }
+                               if ($origword eq "--searchdirs") {
+                                       $selecteddelayed = -2;
                                }
-                               elsif (/[*?[]/) {
-                                       # process wildcards but also plain names (for delayed target removal)
+                               elsif (m,/,) {
+                                       msg( "mail,log", "$_: filename may not contain slashes except for DELAYED/#-day/ prefixes\n" );
+                               }
+                               else {
+                                       # process wildcards but also plain names
                                        my (@thesefiles);
                                        my $pat = quotemeta($_);
                                        $pat =~ s/\\\*/.*/g;
                                        $pat =~ s/\\\?/.?/g;
                                        $pat =~ s/\\([][])/$1/g;
-                                       opendir( DIR, "." );
-                                       push (@thesefiles, grep /^$pat$/, readdir(DIR) );
-                                       closedir( DIR );
-                                       for ( my($adelay)=0; (! @thesefiles) && $adelay <= $conf::max_delayed; $adelay++ ) {
-                                               my($dir) = sprintf( $conf::incoming_delayed,
-                                                                   $adelay );
-                                               opendir( DIR, "$dir" );
-                                               push( @thesefiles, map ("$dir/$_", grep /^$pat$/, readdir(DIR) ));
+
+                                       if ( $selecteddelayed < 0) { # scanning or explicitly incoming
+                                               opendir( DIR, "." );
+                                               push (@thesefiles, grep /^$pat$/, readdir(DIR) );
                                                closedir( DIR );
                                        }
-                                       push (@files, @thesefiles);
-                                       if (! @thesefiles) {
-                                               msg( "mail,log", "$_ did not match anything\n" );
-                                       }
-                               }
-                               else {
-                                   my (@thesefiles);
-                                   $file = $_;
-                                   if (-f $file) {
-                                               push (@thesefiles, $file);
+                                       if ( $selecteddelayed >= 0) {
+                                               my $dir = sprintf( $conf::incoming_delayed, $selecteddelayed );
+                                               opendir( DIR, $dir );
+                                               push( @thesefiles, map ("$dir/$_", grep /^$pat$/, readdir(DIR) ));
+                                               closedir( DIR );
                                        }
-                                       for ( my($adelay)=0; $adelay <= $conf::max_delayed; $adelay++ ) {
-                                               my($dir) = sprintf( $conf::incoming_delayed, $adelay );
-                                               if (-f "$dir/$file") {
-                                                       push (@thesefiles, "$dir/$file");
+                                       elsif ( $selecteddelayed == -2) {
+                                               for ( my($adelay)=0; (! @thesefiles) && $adelay <= $conf::max_delayed; $adelay++ ) {
+                                                       my $dir = sprintf( $conf::incoming_delayed, $adelay );
+                                                       opendir( DIR, $dir);
+                                                       push( @thesefiles, map ("$dir/$_", grep /^$pat$/, readdir(DIR) ));
+                                                       closedir( DIR );
                                                }
-                                   }
-                                       if ($file =~ m/\.changes$/ &&  $conf::upload_method eq "copy") {
-                                               for ( my($adelay)=0; $adelay <= $conf::max_delayed; $adelay++ ) {
-                                                       my($dir) = sprintf( "$conf::targetdir_delayed",$adelay );
-                                                       if (-f "$dir/$file") {
-                                                               push (@thesefiles, "$dir/$file");
-                                                               push (@thesefiles, map( "$dir/$_",get_filelist_from_known_good_changes("$dir/$file")));
-                                                       }
-                                               }
-                                       }
-                                       if (!@thesefiles) {
-                                               msg( "mail,log", "No file found: $file\n" );
                                        }
                                        push (@files, @thesefiles);
+                                       if (! @thesefiles) {
+                                               msg( "mail,log", "$origword did not match anything\n" );
+                                       }
                                }
                        }
                        if (!@files) {
@@ -1138,24 +1132,28 @@ sub process_commands($) {
                                                msg( "mail,log", "$file: rm: $!\n" );
                                        }
                                        else {
+                        $file =~ s,$conf::incoming/?,,;
                                                push( @removed, $file );
                                        }
                                }
                                msg( "mail,log", "Files removed: @removed\n" ) if @removed;
                        }
                }
-               elsif ($word[0] eq "mv") {
+               elsif ($word[0] eq "reschedule") {
                        if (@word != 3) {
                                msg( "mail,log", "Wrong number of arguments\n" );
                        }
+                       elsif ($conf::upload_method ne "copy") {
+                               msg( "mail,log", "reschedule not available\n" );
+                       }
                        elsif ($word[1] =~ m,/, || $word[1] !~ m/\.changes/) {
-                               msg( "mail,log", "$word[1]: filename may not contain slashes\n" );
+                               msg( "mail,log", "$word[1]: filename may not contain slashes and must be .changes\n" );
                        }
                        elsif (! (($target_delay) = $word[2] =~ m,^([0-9]+)-day$,) || $target_delay > $conf::max_delayed) {
-                               msg( "mail,log", "$word[2]: target must be #-day with # between 0 and $conf::max_delayed (in particular, no '/' allowed)\n");
+                               msg( "mail,log", "$word[2]: rescheduling target must be #-day with # between 0 and $conf::max_delayed (in particular, no '/' allowed)\n");
                        }
                        elsif ($word[1] =~ /$conf::keep_files/) {
-                               msg( "mail,log", "$word[1] is protected, cannot rename\n" );
+                               msg( "mail,log", "$word[1] is protected, cannot do stuff with it\n" );
                        }
                        else {
                                my($adelay);
@@ -1174,6 +1172,9 @@ sub process_commands($) {
                                        push (@thesefiles, $word[1]);
                                        push (@thesefiles, get_filelist_from_known_good_changes("$dir/$word[1]"));
                                        for my $afile(@thesefiles) {
+                                               if ($afile =~ m/\.changes$/) {
+                                                       utime undef,undef,("$dir/$afile");
+                                               }
                                                if (! rename "$dir/$afile","$target_dir/$afile") {
                                                        msg( "mail,log", "rename: $!\n" );
                                                }
@@ -1184,6 +1185,45 @@ sub process_commands($) {
                                }
                        }
                }
+               elsif ($word[0] eq "cancel") {
+                       if (@word != 2) {
+                               msg( "mail,log", "Wrong number of arguments\n" );
+                       }
+                       elsif ($conf::upload_method ne "copy") {
+                               msg( "mail,log", "cancel not available\n" );
+                       }
+                       elsif ($word[1] !~ m,^[a-zA-Z0-9.+_:@=%-][~a-zA-Z0-9.+_:@=%-]*\.changes$,) {
+                               msg( "mail,log", "argument to cancel must be one .changes filename without path\n" );
+                       }
+                   my (@files) = ();
+                       for ( my($adelay)=0; $adelay <= $conf::max_delayed; $adelay++ ) {
+                               my($dir) = sprintf( "$conf::targetdir_delayed",$adelay );
+                               if (-f "$dir/$word[1]") {
+                                       @removed = ();
+                                       push (@files, "$word[1]");
+                                       push (@files,get_filelist_from_known_good_changes("$dir/$word[1]"));
+                                       foreach $file ( @files ) {
+                                               if (!-f "$dir/$file") {
+                                                       msg( "mail,log", "$dir/$file: no such file\n" );
+                                               }
+                                               elsif ("$dir/$file" =~ /$conf::keep_files/) {
+                                                       msg( "mail,log", "$dir/$file is protected, cannot ".
+                                                                "remove\n" );
+                                               }
+                                               elsif (!unlink( "$dir/$file" )) {
+                                                       msg( "mail,log", "$dir/$file: rm: $!\n" );
+                                               }
+                                               else {
+                                                       push( @removed, $file );
+                                               }
+                                       }
+                                   msg( "mail,log", "Files removed from $adelay-day: @removed\n" ) if @removed;
+                               }
+                       }
+                       if (!@files) {
+                               msg( "mail,log", "No upload found: $word[1]\n" );
+                       }
+               }
                else {
                        msg( "mail,log", "unknown command $word[0]\n" );
                }
@@ -1204,7 +1244,7 @@ sub age_delayed_queues() {
                }
                for my $achanges (<$dir/*.changes>) {
                        my $mtime = (stat($achanges))[9];
-                       if ($mtime + 24*60*60 <= time) {
+                       if ($mtime + 24*60*60 <= time || $adelay==0) {
                                utime undef,undef,($achanges);
                                my @thesefiles = ($achanges =~ m,.*/([^/]*),);
                                push (@thesefiles, get_filelist_from_known_good_changes($achanges));