3 # wanna-build: coordination script for Debian buildds
4 # Copyright (C) 1998 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
5 # Copyright (C) 2005-2008 Ryan Murray <rmurray@debian.org>
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License as
9 # published by the Free Software Foundation; either version 2 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 $basedir ||= "/var/lib/debbuild";
25 $dbbase ||= "build-db";
26 $transactlog ||= "transactions.log";
27 $mailprog ||= "/usr/sbin/sendmail";
28 require "/org/wanna-build/etc/wanna-build.conf";
29 die "$conf::basedir is not a directory\n" if ! -d $conf::basedir;
30 die "dbbase is empty\n" if ! $dbbase;
31 die "transactlog is empty\n" if ! $transactlog;
32 die "mailprog binary $conf::mailprog does not exist or isn't executable\n"
33 if !-x $conf::mailprog;
34 die "no distributions defined\n" if ! %distributions;
42 use lib '/org/wanna-build/bin';
45 our ($verbose, $mail_logs, $list_order, $list_state,
46 $curr_date, $op_mode, $user, $real_user, $distribution,
47 $fail_reason, $opt_override, $import_from, $export_to, $opt_create_db,
49 $info_all_dists, $arch,
50 $category, %catval, %short_category,
51 $short_date, $list_min_age, $dbbase, @curr_time,
52 $build_priority, %new_vers, $binNMUver, %merge_srcvers, %merge_binsrc);
55 $ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin:/org/wanna-build/bin/";
59 $curr_date = strftime("%Y %b %d %H:%M:%S",@curr_time);
60 $short_date = strftime("%m/%d/%y",@curr_time);
63 # map program invocation names to operation modes
64 my %prognames = ( "uploaded-build" => "set-uploaded",
65 "failed-build" => "set-failed",
66 "no-build" => "set-not-for-us",
67 "give-back-build" => "set-needs-build",
68 "dep-wait-build" => "set-dep-wait",
69 "forget-build" => "forget",
70 "merge-quinn" => "merge-quinn",
71 "merge-packages" => "merge-packages",
72 "merge-sources" => "merge-sources",
73 "build-info" => "info" );
75 %short_category = ( u => "uploaded-fixed-pkg",
82 c => "compiler-error",
86 ($progname = $0) =~ s,.*/,,;
87 if ($prognames{$progname}) {
88 $op_mode = $prognames{$progname};
90 elsif ($progname =~ /^list-(.*)$/) {
92 $list_state = ($1 eq "all") ? "" : $1;
97 verbose => { short => "v", flag => \$verbose },
98 override => { short => "o", flag => \$opt_override },
99 "create-db" => { flag => \$opt_create_db },
100 "correct-compare" => { flag => \$WannaBuild::opt_correct_version_cmp },
101 # TODO: remove after buildds no longer pass to wanna-build
102 "no-propagation" => { short => "N" },
103 "no-down-propagation" => { short => "D" },
105 take => { mode => "set-building" },
106 failed => { short => "f", mode => "set-failed" },
107 uploaded => { short => "u", mode => "set-uploaded" },
108 "no-build" => { short => "n", mode => "set-not-for-us" },
109 built => { mode => "set-built" },
110 attempted => { mode => "set-attempted" },
111 "give-back" => { mode => "set-needs-build" },
112 "dep-wait" => { mode => "set-dep-wait" },
113 forget => { mode => "forget" },
114 'forget-user' => { mode => 'forget-user' },
115 "merge-quinn" => { mode => "merge-quinn" },
116 "merge-partial-quinn" => { mode => "merge-partial-quinn" },
117 "merge-packages" => { mode => "merge-packages" },
118 "merge-sources" => { mode => "merge-sources" },
119 "pretend-avail" => { short => "p", mode => "pretend-avail" },
120 "merge-all" => { mode => "merge-all" },
121 "merge-all-overlay" => { mode => "merge-all-overlay" },
122 info => { short => "i", mode => "info" },
123 'binNMU' => { mode => 'set-binary-nmu', arg => \$binNMUver,
124 code => sub { die "Invalid binNMU version: $binNMUver\n"
125 if $binNMUver !~ /^([\d]*)$/ and $1 >= 0; } },
126 'perm-build-priority' => { mode => "set-permanent-build-priority", arg => \$build_priority,
127 code => sub { die "Invalid build priority: $build_priority\n"
128 if $build_priority !~ /^-?[\d]+$/; } },
129 'build-priority' => { mode => "set-build-priority", arg => \$build_priority,
130 code => sub { die "Invalid build priority: $build_priority\n"
131 if $build_priority !~ /^-?[\d]+$/; } },
133 { short => "l", mode => "list", arg => \$list_state,
135 die "Unknown state to list: $list_state\n"
136 if !isin( $list_state, qw(needs-build building uploaded
137 built build-attempted failed installed dep-wait
138 not-for-us all failed-removed
139 install-wait reupload-wait bd-uninstallable));} },
142 { short => "d", arg => \$distribution,
144 if ($distribution eq "a" || $distribution eq "all") {
149 $distribution = "oldstable" if $distribution eq "o";
150 $distribution = "stable" if $distribution eq "s";
151 $distribution = "testing" if $distribution eq "t";
152 $distribution = "unstable" if $distribution eq "u";
156 { short => "O", arg => \$list_order,
158 die "Bad ordering character\n"
159 if $list_order !~ /^[PSpsncb]+$/;
161 message => { short => "m", arg => \$fail_reason },
162 # database is deprecated, use arch instead.
163 database => { short => "b", arg => \$conf::dbbase },
164 arch => { short => "A", arg => \$arch },
165 user => { short => "U", arg => \$user },
166 category => { short => "c", arg => \$category,
168 $category = $short_category{$category}
169 if exists $short_category{$category};
170 die "Unknown category: $category\n"
171 if !isin( $category, values %short_category );
173 "min-age" => { short => "a", arg => \$list_min_age,
175 die "Argument of --min-age must be a non-zero number\n"
176 if $list_min_age == 0;
178 "max-age" => { arg => \$list_min_age,
180 die "Argument of --max-age must be a non-zero number\n"
181 if $list_min_age == 0;
185 export => { arg => \$export_to, mode => "export" },
186 import => { arg => \$import_from, mode => "import" },
187 "manual-edit" => { mode => "manual-edit" },
190 while( @ARGV && $ARGV[0] =~ /^-/ ) {
193 my($opt, $optname, $arg);
194 if (/^--([^=]+)(=|$)/) {
196 $opt = $options{$optname};
197 $arg = $1 if /^--\Q$optname\E=((.|\n)*)$/;
200 $optname = substr( $_, 1, 1 );
201 $opt = (grep { defined($_->{short}) ? $_->{short} eq $optname : 0} values %options)[0];
202 $arg = $1 if /^-$optname(.+)$/;
205 warn "Unknown option: --$1\n";
210 die "$optname option missing argument\n" if !@ARGV;
213 ${$opt->{arg}} = $arg;
215 elsif (defined $arg) {
216 die "Option $optname takes no argument\n";
220 die "Conflicting operation modes\n" if $op_mode;
221 $op_mode = $opt->{mode};
231 $op_mode = $category ? "set-failed" : "set-building"
232 if !$op_mode; # default operation
233 $list_order = $list_state eq "failed" ? 'fPcpsn' : 'PScpsn'
234 if !$list_order and $list_state;
235 $distribution ||= "unstable";
236 die "Bad distribution '$distribution'\n"
237 if !isin($distribution, keys %conf::distributions);
239 # If they didn't specify an arch, try to get it from database name which
240 # is in the form of $arch/build-db
241 # This is for backwards compatibity with older versions that didn't
242 # specify the arch yet.
243 $conf::dbbase =~ m#^([^/]+)#;
246 # TODO: Check that it's an known arch (for that dist), and give
250 my $version = '$Revision: db181a534e9d $ $Date: 2008/03/26 06:20:22 $ $Author: rmurray $';
251 $version =~ s/(^\$| \$ .*$)//g;
252 print "wanna-build $version for $distribution on $arch\n";
255 if (!@ARGV && !isin( $op_mode, qw(list merge-quinn merge-partial-quinn import export
256 merge-packages manual-edit
258 warn "No packages given.\n";
262 $real_user = (getpwuid($<))[0];
263 die "Can't determine your user name\n"
264 if $op_mode ne "list" && !$user &&
265 !($user = $real_user);
268 if ($op_mode eq "set-failed" && !$category) {
269 print "Enter reason for failing (end with '.' alone on ".
274 last if $line eq ".\n";
275 $fail_reason .= $line;
277 chomp( $fail_reason );
278 } elsif ($op_mode eq "set-dep-wait") {
279 print "Enter dependencies (one line):\n";
281 while( !$line && !eof(STDIN) ) {
282 chomp( $line = <STDIN> );
284 die "No dependencies given\n" if !$line;
285 $fail_reason = $line;
286 } elsif ($op_mode eq "set-binary-nmu" and $binNMUver > 0) {
287 print "Enter changelog entry (one line):\n";
289 while( !$line && !eof(STDIN) ) {
290 chomp( $line = <STDIN> );
292 die "No changelog entry given\n" if !$line;
293 $fail_reason = $line;
302 $dbh->disconnect or warn $dbh->errstr;
306 my $schema_suffix = '';
307 if (isin( $op_mode, qw(list info)) && $distribution !~ /security/ && !(not -t and $user =~ /-/)) {
308 $dbh = DBI->connect("DBI:Pg:service=wanna-build") ||
309 die "FATAL: Cannot open database: $DBI::errstr\n";
310 $schema_suffix = '_public';
314 $dbh = DBI->connect("DBI:Pg:service=wanna-build-privileged") ||
315 die "FATAL: Cannot open database: $DBI::errstr\n";
318 # TODO: This shouldn't be needed, file a bug.
319 $dbh->{pg_server_prepare} = 0;
321 $dbh->begin_work or die $dbh->errstr;
328 if ($mail_logs && $conf::log_mail) {
329 send_mail( $conf::log_mail,
330 "wanna-build $distribution state changes $curr_date",
331 "State changes at $curr_date for distribution ".
332 "$distribution:\n\n$mail_logs\n" );
340 SWITCH: foreach ($op_mode) {
342 add_packages( $1, @ARGV );
346 list_packages( $list_state );
350 info_packages( @ARGV );
353 /^forget-user/ && do {
354 die "This operation is restricted to admin users\n"
355 if (defined @conf::admin_users and
356 !isin( $real_user, @conf::admin_users));
357 forget_users( @ARGV );
361 forget_packages( @ARGV );
364 /^merge-partial-quinn/ && do {
365 die "This operation is restricted to admin users\n"
366 if (defined @conf::admin_users and
367 !isin( $real_user, @conf::admin_users));
372 /^merge-quinn/ && do {
373 die "This operation is restricted to admin users\n"
374 if (defined @conf::admin_users and
375 !isin( $real_user, @conf::admin_users));
380 /^merge-packages/ && do {
381 die "This operation is restricted to admin users\n"
382 if (defined @conf::admin_users and
383 !isin( $real_user, @conf::admin_users));
388 /^merge-sources/ && do {
389 die "This operation is restricted to admin users\n"
390 if (defined @conf::admin_users and
391 !isin( $real_user, @conf::admin_users));
396 /^pretend-avail/ && do {
397 pretend_avail( @ARGV );
400 /^merge-all$/ && do {
401 die "This operation is restricted to admin users\n"
402 if (defined @conf::admin_users and
403 !isin( $real_user, @conf::admin_users));
406 @ARGV = ( $ARGS[0] );
407 my $pkgs = parse_packages();
408 @ARGV = ( $ARGS[1] );
410 @ARGV = ( $ARGS[2] );
411 my $srcs = parse_sources(1);
412 call_edos_depcheck( $ARGS[0], $srcs );
415 /^merge-all-overlay/ && do {
416 die "This operation is restricted to admin users\n"
417 if (defined @conf::admin_users and
418 !isin( $real_user, @conf::admin_users));
421 @ARGV = ( $ARGS[0] );
422 my $pkgs = parse_packages();
423 @ARGV = ( $ARGS[1] );
425 @ARGV = ( $ARGS[2] );
426 my $srcs = parse_sources(1);
427 call_edos_depcheck( $ARGS[3], $srcs );
431 die "This operation is restricted to admin users\n"
432 if (defined @conf::admin_users and
433 !isin( $real_user, @conf::admin_users));
434 $dbh->do("DELETE from " . table_name() .
435 " WHERE distribution = ?", undef,
439 read_db( $import_from );
443 export_db( $export_to );
447 die "Unexpected operation mode $op_mode\n";
449 if (not -t and $user =~ /-/) {
450 my $userinfo = get_user_info($user);
451 if (!defined $userinfo)
453 add_user_info($user);
457 update_user_info($user);
463 my $newstate = shift;
464 my( $package, $name, $version, $ok, $reason );
466 foreach $package (@_) {
467 $package =~ s,^.*/,,; # strip path
468 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
469 $package =~ s/_[a-zA-Z\d-]+\.changes$//; # strip extension
470 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
471 ($name,$version) = ($1,$2);
474 warn "$package: can't extract package name and version ".
479 if ($op_mode eq "set-building") {
480 add_one_building( $name, $version );
482 elsif ($op_mode eq "set-built") {
483 add_one_built( $name, $version );
485 elsif ($op_mode eq "set-attempted") {
486 add_one_attempted( $name, $version );
488 elsif ($op_mode eq "set-uploaded") {
489 add_one_uploaded( $name, $version );
491 elsif ($op_mode eq "set-failed") {
492 add_one_failed( $name, $version );
494 elsif ($op_mode eq "set-not-for-us") {
495 add_one_notforus( $name, $version );
497 elsif ($op_mode eq "set-needs-build") {
498 add_one_needsbuild( $name, $version );
500 elsif ($op_mode eq "set-dep-wait") {
501 add_one_depwait( $name, $version );
503 elsif ($op_mode eq "set-build-priority") {
504 set_one_buildpri( $name, $version, 'buildpri' );
506 elsif ($op_mode eq "set-permanent-build-priority") {
507 set_one_buildpri( $name, $version, 'permbuildpri' );
509 elsif ($op_mode eq "set-binary-nmu") {
510 set_one_binnmu( $name, $version );
515 sub add_one_building {
521 my $pkg = get_source_info($name);
523 if ($pkg->{'state'} eq "Not-For-Us") {
525 $reason = "not suitable for this architecture";
527 elsif ($pkg->{'state'} =~ /^Dep-Wait/) {
529 $reason = "not all source dependencies available yet";
531 elsif ($pkg->{'state'} =~ /^BD-Uninstallable/) {
533 $reason = "source dependencies are not installable";
535 elsif ($pkg->{'state'} eq "Uploaded" &&
536 (version_lesseq($version, $pkg->{'version'}))) {
538 $reason = "already uploaded by $pkg->{'builder'}";
539 $reason .= " (in newer version $pkg->{'version'})"
540 if !version_eq($pkg, $version);
542 elsif ($pkg->{'state'} eq "Installed" &&
543 version_less($version,$pkg->{'version'})) {
545 print "$name: Warning: newer version $pkg->{'version'} ".
546 "already installed, but overridden.\n";
550 $reason = "newer version $pkg->{'version'} already in ".
551 "archive; doesn't need rebuilding";
552 print "$name: Note: If the following is due to an epoch ",
553 " change, use --override\n";
556 elsif ($pkg->{'state'} eq "Installed" &&
557 pkg_version_eq($pkg,$version)) {
559 $reason = "is up-to-date in the archive; doesn't need rebuilding";
561 elsif ($pkg->{'state'} eq "Needs-Build" &&
562 version_less($version,$pkg->{'version'})) {
564 print "$name: Warning: newer version $pkg->{'version'} ".
565 "needs building, but overridden.";
569 $reason = "newer version $pkg->{'version'} needs building, ".
573 elsif (isin($pkg->{'state'},qw(Building Built Build-Attempted))) {
574 if (version_less($pkg->{'version'},$version)) {
575 print "$name: Warning: Older version $pkg->{'version'} ",
576 "is being built by $pkg->{'builder'}\n";
577 if ($pkg->{'builder'} ne $user) {
578 send_mail( $pkg->{'builder'},
579 "package takeover in newer version",
580 "You are building package '$name' in ".
581 "version $version\n".
582 "(as far as I'm informed).\n".
583 "$user now has taken the newer ".
584 "version $version for building.".
585 "You can abort the build if you like.\n" );
590 print "User $pkg->{'builder'} had already ",
591 "taken the following package,\n",
592 "but overriding this as you request:\n";
593 send_mail( $pkg->{'builder'}, "package takeover",
594 "The package '$name' (version $version) that ".
595 "was taken by you\n".
596 "has been taken over by $user\n" );
598 elsif ($pkg->{'builder'} eq $user) {
599 print "$name: Note: already taken by you.\n";
600 print "$name: ok\n" if $verbose;
605 $reason = "already taken by $pkg->{'builder'}";
606 $reason .= " (in newer version $pkg->{'version'})"
607 if !version_eq($pkg->{'version'}, $version);
611 elsif ($pkg->{'state'} =~ /^Failed/ &&
612 pkg_version_eq($pkg, $version)) {
614 print "The following package previously failed ",
615 "(by $pkg->{'builder'})\n",
616 "but overriding this as you request:\n";
617 send_mail( $pkg->{'builder'}, "failed package takeover",
618 "The package '$name' (version $version) that ".
620 "and has failed previously has been taken over ".
622 if $pkg->{'builder'} ne $user;
626 $reason = "build of $version failed previously:\n ";
627 $reason .= join( "\n ", split( "\n", $pkg->{'failed'} ));
628 $reason .= "\nalso the package doesn't need builing"
629 if $pkg->{'state'} eq 'Failed-Removed';
635 if ($pkg->{'binary_nmu_version'}) {
636 print "$name: Warning: needs binary NMU $pkg->{'binary_nmu_version'}\n" .
637 "$pkg->{'binary_nmu_changelog'}\n";
640 print "$name: Warning: Previous version failed!\n"
641 if $pkg->{'previous_state'} =~ /^Failed/ ||
642 $pkg->{'state'} =~ /^Failed/;
644 change_state( \$pkg, 'Building' );
645 $pkg->{'package'} = $name;
646 $pkg->{'version'} = $version;
647 $pkg->{'builder'} = $user;
648 log_ta( $pkg, "--take" );
649 update_source_info($pkg);
650 print "$name: $ok\n" if $verbose;
653 print "$name: NOT OK!\n $reason\n";
657 sub add_one_attempted {
660 my $pkg = get_source_info($name);
662 if (!defined($pkg)) {
663 print "$name: not registered yet.\n";
667 if ($pkg->{'state'} ne "Building" ) {
668 print "$name: not taken for building (state is $pkg->{'state'}). ",
672 if ($pkg->{'builder'} ne $user) {
673 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
676 elsif ( !pkg_version_eq($pkg, $version) ) {
677 print "$name: version mismatch ".
678 "$(pkg->{'version'} ".
679 "by $pkg->{'builder'})\n";
683 change_state( \$pkg, 'Build-Attempted' );
684 log_ta( $pkg, "--attempted" );
685 update_source_info($pkg);
686 print "$name: registered as uploaded\n" if $verbose;
692 my $pkg = get_source_info($name);
694 if (!defined($pkg)) {
695 print "$name: not registered yet.\n";
699 if ($pkg->{'state'} ne "Building" ) {
700 print "$name: not taken for building (state is $pkg->{'state'}). ",
704 if ($pkg->{'builder'} ne $user) {
705 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
708 elsif ( !pkg_version_eq($pkg, $version) ) {
709 print "$name: version mismatch ".
710 "$(pkg->{'version'} ".
711 "by $pkg->{'builder'})\n";
714 change_state( \$pkg, 'Built' );
715 log_ta( $pkg, "--built" );
716 update_source_info($pkg);
717 print "$name: registered as built\n" if $verbose;
720 sub add_one_uploaded {
723 my $pkg = get_source_info($name);
725 if (!defined($pkg)) {
726 print "$name: not registered yet.\n";
730 if ($pkg->{'state'} eq "Uploaded" &&
731 pkg_version_eq($pkg,$version)) {
732 print "$name: already uploaded\n";
735 if (!isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
736 print "$name: not taken for building (state is $pkg->{'state'}). ",
740 if ($pkg->{'builder'} ne $user) {
741 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
744 # strip epoch -- buildd-uploader used to go based on the filename.
745 # (to remove at some point)
747 ($pkgver = $pkg->{'version'}) =~ s/^\d+://;
748 $version =~ s/^\d+://; # for command line use
749 if ($pkg->{'binary_nmu_version'} ) {
750 my $nmuver = binNMU_version($pkgver, $pkg->{'binary_nmu_version'});
751 if (!version_eq( $nmuver, $version )) {
752 print "$name: version mismatch ($nmuver registered). ",
756 } elsif (!version_eq($pkgver, $version)) {
757 print "$name: version mismatch ($pkg->{'version'} registered). ",
762 change_state( \$pkg, 'Uploaded' );
763 log_ta( $pkg, "--uploaded" );
764 update_source_info($pkg);
765 print "$name: registered as uploaded\n" if $verbose;
772 my $pkg = get_source_info($name);
774 if (!defined($pkg)) {
775 print "$name: not registered yet.\n";
778 $state = $pkg->{'state'};
780 if ($state eq "Not-For-Us") {
781 print "$name: not suitable for this architecture anyway. Skipping.\n";
784 elsif ($state eq "Failed-Removed") {
785 print "$name: failed previously and doesn't need building. Skipping.\n";
788 elsif ($state eq "Installed") {
789 print "$name: Is already installed in archive. Skipping.\n";
792 elsif ($pkg->{'builder'} &&
793 (($user ne $pkg->{'builder'}) &&
794 !($pkg->{'builder'} =~ /^(\w+)-\w+/ && $1 eq $user))) {
795 print "$name: not taken by you, but by ".
796 "$pkg->{'builder'}. Skipping.\n";
799 elsif ( !pkg_version_eq($pkg, $version) ) {
800 print "$name: version mismatch ".
801 "$(pkg->{'version'} ".
802 "by $pkg->{'builder'})\n";
807 if (!$cat && $fail_reason =~ /^\[([^\]]+)\]/) {
809 $cat = $short_category{$cat} if exists $short_category{$cat};
810 if (!isin( $cat, values %short_category )) {
811 print "$name: Warning: unknown category $cat; discarded\n";
814 $fail_reason =~ s/^\[[^\]]+\][ \t]*\n*//;
817 if ($state eq "Needs-Build") {
818 print "$name: Warning: not registered for building previously, ".
819 "but processing anyway.\n";
821 elsif ($state eq "Uploaded") {
822 print "$name: Warning: marked as uploaded previously, ".
823 "but processing anyway.\n";
825 elsif ($state eq "Dep-Wait") {
826 print "$name: Warning: marked as waiting for dependencies, ".
827 "but processing anyway.\n";
829 elsif ($state eq "BD-Uninstallable") {
830 print "$name: Warning: marked as having uninstallable build-dependencies, ".
831 "but processing anyway.\n";
833 elsif ($state eq "Failed") {
834 print "$name: already registered as failed; will append new message\n"
836 print "$name: already registered as failed; changing category\n"
840 if (($cat eq "reminder-sent" || $cat eq "nmu-offered") &&
841 defined $pkg->{'failed_category'} &&
842 $pkg->{'failed_category'} ne $cat) {
843 (my $action = $cat) =~ s/-/ /;
844 $fail_reason .= "\n$short_date: $action";
847 change_state( \$pkg, 'Failed' );
848 $pkg->{'builder'} = $user;
849 $pkg->{'failed'} .= "\n" if $pkg->{'failed'};
850 $pkg->{'failed'} .= $fail_reason;
851 $pkg->{'failed_category'} = $cat if $cat;
852 if (defined $pkg->{'permbuildpri'}) {
853 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
855 delete $pkg->{'buildpri'};
857 log_ta( $pkg, "--failed" );
858 update_source_info($pkg);
859 print "$name: registered as failed\n" if $verbose;
862 sub add_one_notforus {
865 my $pkg = get_source_info($name);
867 if ($pkg->{'state'} eq 'Not-For-Us') {
868 # reset Not-For-Us state in case it's called twice; this is
869 # the only way to get a package out of this state...
870 # There is no really good state in which such packages should
871 # be put :-( So use Failed for now.
872 change_state( \$pkg, 'Failed' );
873 $pkg->{'package'} = $name;
874 $pkg->{'failed'} = "Was Not-For-Us previously";
875 delete $pkg->{'builder'};
876 delete $pkg->{'depends'};
877 log_ta( $pkg, "--no-build(rev)" );
878 print "$name: now not unsuitable anymore\n";
880 send_mail( $conf::notforus_maint,
881 "$name moved out of Not-For-Us state",
882 "The package '$name' has been moved out of the Not-For-Us ".
884 "It should probably also be removed from ".
885 "Packages-arch-specific or\n".
886 "the action was wrong.\n" )
887 if $conf::notforus_maint;
890 change_state( \$pkg, 'Not-For-Us' );
891 $pkg->{'package'} = $name;
892 delete $pkg->{'builder'};
893 delete $pkg->{'depends'};
894 delete $pkg->{'buildpri'};
895 delete $pkg->{'binary_nmu_version'};
896 delete $pkg->{'binary_nmu_changelog'};
897 log_ta( $pkg, "--no-build" );
898 print "$name: registered as unsuitable\n" if $verbose;
900 send_mail( $conf::notforus_maint,
901 "$name set to Not-For-Us",
902 "The package '$name' has been set to state Not-For-Us ".
904 "It should probably also be added to ".
905 "Packages-arch-specific or\n".
906 "the Not-For-Us state is wrong.\n" )
907 if $conf::notforus_maint;
909 update_source_info($pkg);
912 sub add_one_needsbuild {
916 my $pkg = get_source_info($name);
918 if (!defined($pkg)) {
919 print "$name: not registered; can't give back.\n";
922 $state = $pkg->{'state'};
924 if ($state eq "BD-Uninstallable") {
926 print "$name: Forcing uninstallability mark to be removed. This is not permanent and might be reset with the next trigger run\n";
928 change_state( \$pkg, 'Needs-Build' );
929 delete $pkg->{'builder'};
930 delete $pkg->{'depends'};
931 log_ta( $pkg, "--give-back" );
932 update_source_info($pkg);
933 print "$name: given back\n" if $verbose;
937 print "$name: has uninstallable build-dependencies. Skipping\n",
938 " (use --override to clear dependency list and ",
939 "give back anyway)\n";
943 elsif ($state eq "Dep-Wait") {
945 print "$name: Forcing source dependency list to be cleared\n";
948 print "$name: waiting for source dependencies. Skipping\n",
949 " (use --override to clear dependency list and ",
950 "give back anyway)\n";
954 elsif (!isin( $state, qw(Building Built Build-Attempted))) {
955 print "$name: not taken for building (state is $state).";
957 print "\n$name: Forcing give-back\n";
960 print " Skipping.\n";
964 if (defined ($pkg->{'builder'}) && $user ne $pkg->{'builder'} &&
965 !($pkg->{'builder'} =~ /^(\w+)-\w+/ && $1 eq $user) &&
967 print "$name: not taken by you, but by ".
968 "$pkg->{'builder'}. Skipping.\n";
971 if (!pkg_version_eq($pkg, $version)) {
972 print "$name: version mismatch ($pkg->{'version'} registered). ",
976 if ($distribution eq "unstable") {
977 change_state( \$pkg, 'BD-Uninstallable' );
978 $pkg->{'bd_problem'} = "Installability of build dependencies not tested yet";
980 change_state( \$pkg, 'Needs-Build' );
982 $pkg->{'builder'} = undef;
983 $pkg->{'depends'} = undef;
984 log_ta( $pkg, "--give-back" );
985 update_source_info($pkg);
986 print "$name: given back\n" if $verbose;
992 my $pkg = get_source_info($name);
995 if (!defined($pkg)) {
996 print "$name: not registered; can't register for binNMU.\n";
999 my $db_ver = $pkg->{'version'};
1001 if (!version_eq($db_ver, $version)) {
1002 print "$name: version mismatch ($db_ver registered). ",
1006 $state = $pkg->{'state'};
1008 if (defined $pkg->{'binary_nmu_version'}) {
1009 if ($binNMUver == 0) {
1010 change_state( \$pkg, 'Installed' );
1011 delete $pkg->{'builder'};
1012 delete $pkg->{'depends'};
1013 delete $pkg->{'binary_nmu_version'};
1014 delete $pkg->{'binary_nmu_changelog'};
1015 } elsif ($binNMUver <= $pkg->{'binary_nmu_version'}) {
1016 print "$name: already building binNMU $pkg->{'binary_nmu_version'}\n";
1019 $pkg->{'binary_nmu_version'} = $binNMUver;
1020 $pkg->{'binary_nmu_changelog'} = $fail_reason;
1021 $pkg->{'notes'} = 'out-of-date';
1022 $pkg->{'buildpri'} = $pkg->{'permbuildpri'}
1023 if (defined $pkg->{'permbuildpri'});
1025 log_ta( $pkg, "--binNMU" );
1026 update_source_info($pkg);
1028 } elsif ($binNMUver == 0) {
1029 print "${name}_$version: no scheduled binNMU to cancel.\n";
1033 if ($state ne 'Installed') {
1034 print "${name}_$version: not installed; can't register for binNMU.\n";
1038 my $fullver = binNMU_version($version,$binNMUver);
1039 if ( version_lesseq( $fullver, $pkg->{'installed_version'} ) )
1041 print "$name: binNMU $fullver is not newer than current version $pkg->{'installed_version'}\n";
1045 if ($distribution eq "unstable") {
1046 change_state( \$pkg, 'BD-Uninstallable' );
1047 $pkg->{'bd_problem'} = "Installability of build dependencies not tested yet";
1051 change_state( \$pkg, 'Needs-Build' );
1053 delete $pkg->{'builder'};
1054 delete $pkg->{'depends'};
1055 $pkg->{'binary_nmu_version'} = $binNMUver;
1056 $pkg->{'binary_nmu_changelog'} = $fail_reason;
1057 $pkg->{'notes'} = 'out-of-date';
1058 log_ta( $pkg, "--binNMU" );
1059 update_source_info($pkg);
1060 print "${name}: registered for binNMU $fullver\n" if $verbose;
1063 sub set_one_buildpri {
1065 my $version = shift;
1067 my $pkg = get_source_info($name);
1070 if (!defined($pkg)) {
1071 print "$name: not registered; can't set priority.\n";
1074 $state = $pkg->{'state'};
1076 if ($state eq "Not-For-Us") {
1077 print "$name: not suitable for this architecture. Skipping.\n";
1079 } elsif ($state eq "Failed-Removed") {
1080 print "$name: failed previously and doesn't need building. Skipping.\n";
1083 if (!pkg_version_eq($pkg, $version)) {
1084 print "$name: version mismatch ($pkg->{'version'} registered). ",
1088 if ( $build_priority == 0 ) {
1089 delete $pkg->{'buildpri'}
1090 if $key eq 'permbuildpri' and defined $pkg->{'buildpri'}
1091 and $pkg->{'buildpri'} == $pkg->{$key};
1092 delete $pkg->{$key};
1094 $pkg->{'buildpri'} = $build_priority
1095 if $key eq 'permbuildpri';
1096 $pkg->{$key} = $build_priority;
1098 update_source_info($pkg);
1099 print "$name: set to build priority $build_priority\n" if $verbose;
1102 sub add_one_depwait {
1104 my $version = shift;
1106 my $pkg = get_source_info($name);
1108 if (!defined($pkg)) {
1109 print "$name: not registered yet.\n";
1112 $state = $pkg->{'state'};
1114 if ($state eq "Dep-Wait") {
1115 print "$name: merging with previously registered dependencies\n";
1118 if (isin( $state, qw(Needs-Build Failed BD-Uninstallable))) {
1119 print "$name: Warning: not registered for building previously, ".
1120 "but processing anyway.\n";
1122 elsif ($state eq "Not-For-Us") {
1123 print "$name: not suitable for this architecture anyway. Skipping.\n";
1126 elsif ($state eq "Failed-Removed") {
1127 print "$name: failed previously and doesn't need building. Skipping.\n";
1130 elsif ($state eq "Installed") {
1131 print "$name: Is already installed in archive. Skipping.\n";
1134 elsif ($state eq "Uploaded") {
1135 print "$name: Is already uploaded. Skipping.\n";
1138 elsif ($pkg->{'builder'} &&
1139 $user ne $pkg->{'builder'}) {
1140 print "$name: not taken by you, but by ".
1141 "$pkg->{'builder'}. Skipping.\n";
1144 elsif ( !pkg_version_eq($pkg,$version)) {
1145 print "$name: version mismatch ".
1146 "($pkg->{'version'} ".
1147 "by $pkg->{'builder'})\n";
1150 elsif ($fail_reason =~ /^\s*$/ ||
1151 !parse_deplist( $fail_reason, 1 )) {
1152 print "$name: Bad dependency list\n";
1155 change_state( \$pkg, 'Dep-Wait' );
1156 $pkg->{'builder'} = $user;
1157 if (defined $pkg->{'permbuildpri'}) {
1158 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
1160 delete $pkg->{'buildpri'};
1162 my $deplist = parse_deplist( $pkg->{'depends'} );
1163 my $new_deplist = parse_deplist( $fail_reason );
1164 # add new dependencies, maybe overwriting old entries
1165 foreach (keys %$new_deplist) {
1166 $deplist->{$_} = $new_deplist->{$_};
1168 $pkg->{'depends'} = build_deplist($deplist);
1169 log_ta( $pkg, "--dep-wait" );
1170 update_source_info($pkg);
1171 print "$name: registered as waiting for dependencies\n" if $verbose;
1181 my $db = get_all_source_info();
1183 local($/) = ""; # read in paragraph mode
1185 my( $version, $arch, $section, $priority, $builddep, $buildconf, $binaries );
1187 /^Package:\s*(\S+)$/mi and $name = $1;
1188 /^Version:\s*(\S+)$/mi and $version = $1;
1189 /^Architecture:\s*(\S+)$/mi and $arch = $1;
1190 /^Section:\s*(\S+)$/mi and $section = $1;
1191 /^Priority:\s*(\S+)$/mi and $priority = $1;
1192 /^Build-Depends:\s*(.*)$/mi and $builddep = $1;
1193 /^Build-Conflicts:\s*(.*)$/mi and $buildconf = $1;
1194 /^Binary:\s*(.*)$/mi and $binaries = $1;
1196 next if (defined $srcver{$name} and version_less( $version, $srcver{$name} ));
1197 $srcver{$name} = $version;
1199 $pkgs{$name}{'ver'} = $version;
1200 $pkgs{$name}{'bin'} = $binaries;
1201 $pkgs{$name}{'dep'} = $builddep;
1202 $pkgs{$name}{'conf'} = $buildconf;
1203 my $pkg = $db->{$name};
1208 if ($arch eq "all" && !version_less( $version, $pkg->{'version'} )) {
1209 # package is now Arch: all, delete it from db
1210 change_state( \$pkg, 'deleted' );
1211 log_ta( $pkg, "--merge-sources" );
1212 print "$name ($pkg->{'version'}): deleted ".
1213 "from database, because now Arch: all\n"
1215 del_source_info($name);
1216 delete $db->{$name};
1220 # The "Version" should always be the source version --
1221 # not a possible binNMU version number.
1222 $pkg->{'version'} = $version, $change++
1223 if ($pkg->{'state'} eq 'Installed' and
1224 !version_eq( $pkg->{'version'}, $version));
1225 # Always update priority and section, if available
1226 $pkg->{'priority'} = $priority, $change++
1227 if defined $priority and (not defined($pkg->{'priority'}) or $pkg->{'priority'} ne $priority);
1229 $pkg->{'section'} = $section, $change++
1230 if defined $section and (not defined($pkg->{'section'}) or $pkg->{'section'} ne $section);
1232 update_source_info($pkg) if $change;
1235 # Now that we only have the latest source version, build the list
1236 # of binary packages from the Sources point of view
1237 foreach $name (keys %pkgs) {
1238 foreach my $bin (split( /\s*,\s*/, $pkgs{$name}{'bin'} ) ) {
1239 $merge_binsrc{$bin} = $name;
1242 # remove installed packages that no longer have source available
1243 # or binaries installed
1244 foreach $name (keys %$db) {
1245 next if $name =~ /^_/;
1246 my $pkg = $db->{$name};
1247 if (not defined($pkgs{$name})) {
1248 change_state( \$pkg, 'deleted' );
1249 log_ta( $pkg, "--merge-sources" );
1250 print "$name ($pkg->{'version'}): ".
1251 "deleted from database, because ".
1252 "not in Sources anymore\n"
1254 del_source_info($name);
1255 delete $db->{$name};
1257 next if !isin( $pkg->{'state'}, qw(Installed) );
1258 if ($full && not defined $merge_srcvers{$name}) {
1259 change_state( \$pkg, 'deleted' );
1260 log_ta( $pkg, "--merge-sources" );
1261 print "$name ($pkg->{'version'}): ".
1262 "deleted from database, because ".
1263 "binaries don't exist anymore\n"
1265 del_source_info($name);
1266 delete $db->{$name};
1267 } elsif ($full && version_less( $merge_srcvers{$name}, $pkg->{'version'})) {
1268 print "$name ($pkg->{'version'}): ".
1269 "package is Installed but binaries are from ".
1270 $merge_srcvers{$name}. "\n"
1278 # This function looks through a Packages file and sets the state of
1279 # packages to 'Installed'
1280 sub parse_packages {
1283 my $pkgs = get_all_source_info();
1284 local($/) = ""; # read in paragraph mode
1286 my( $name, $version, $depends, $source, $sourcev, $architecture, $provides, $binaryv, $binnmu );
1288 /^Package:\s*(\S+)$/mi and $name = $1;
1289 /^Version:\s*(\S+)$/mi and $version = $1;
1290 /^Depends:\s*(.*)$/mi and $depends = $1;
1291 /^Source:\s*(\S+)(\s*\((\S+)\))?$/mi and ($source,$sourcev) = ($1, $3);
1292 /^Architecture:\s*(\S+)$/mi and $architecture = $1;
1293 /^Provides:\s*(.*)$/mi and $provides = $1;
1294 next if !$name || !$version;
1295 next if ($arch ne $architecture and $architecture ne "all");
1296 next if (defined ($installed->{$name}) and $installed->{$name}{'version'} ne "" and
1297 version_lesseq( $version, $installed->{$name}{'version'} ));
1298 $installed->{$name}{'version'} = $version;
1299 $installed->{$name}{'depends'} = $depends;
1300 $installed->{$name}{'all'} = 1 if $architecture eq "all";
1301 undef $installed->{$name}{'Provider'};
1302 $installed->{$name}{'Source'} = $source ? $source : $name;
1304 foreach (split( /\s*,\s*/, $provides )) {
1305 if (not defined ($installed->{$_})) {
1306 $installed->{$_}{'version'} = "";
1307 $installed->{$_}{'Provider'} = $name;
1311 if ( $version =~ /\+b(\d+)$/ ) {
1314 $version = $sourcev if $sourcev;
1315 $binaryv = $version;
1316 $binaryv =~ s/\+b\d+$//;
1317 $installed->{$name}{'Sourcev'} = $sourcev ? $sourcev : $binaryv;
1318 $binaryv .= "+b$binnmu" if defined($binnmu);
1320 next if $architecture ne $arch;
1321 $name = $source if $source;
1322 next if defined($merge_srcvers{$name}) and $merge_srcvers{$name} eq $version;
1323 $merge_srcvers{$name} = $version;
1325 my $pkg = $pkgs->{$name};
1328 if (isin( $pkg->{'state'}, qw(Not-For-Us)) ||
1329 (isin($pkg->{'state'}, qw(Installed)) &&
1330 version_lesseq($binaryv, $pkg->{'installed_version'}))) {
1331 print "Skipping $name because State == $pkg->{'state'}\n"
1335 if ($pkg->{'binary_nmu_version'} ) {
1336 my $nmuver = binNMU_version($pkg->{'version'}, $pkg->{'binary_nmu_version'});
1337 if (version_less( $binaryv, $nmuver )) {
1338 print "Skipping $name ($version) because have newer ".
1339 "version ($nmuver) in db.\n"
1343 } elsif (version_less($version, $pkg->{'version'})) {
1344 print "Skipping $name ($version) because have newer ".
1345 "version ($pkg->{'version'}) in db.\n"
1350 if (!pkg_version_eq($pkg, $version) &&
1351 $pkg->{'state'} ne "Installed") {
1352 warn "Warning: $name: newer version than expected appeared ".
1353 "in archive ($version vs. $pkg->{'version'})\n";
1354 delete $pkg->{'builder'};
1357 if (!isin( $pkg->{'state'}, qw(Uploaded) )) {
1358 warn "Warning: Package $name was not in uploaded state ".
1359 "before (but in '$pkg->{'state'}').\n";
1360 delete $pkg->{'builder'};
1361 delete $pkg->{'depends'};
1365 $pkg->{'version'} = $version;
1368 change_state( \$pkg, 'Installed' );
1369 $pkg->{'package'} = $name;
1370 $pkg->{'installed_version'} = $binaryv;
1371 if (defined $pkg->{'permbuildpri'}) {
1372 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
1374 delete $pkg->{'buildpri'};
1376 $pkg->{'version'} = $version
1377 if version_less( $pkg->{'version'}, $version);
1378 delete $pkg->{'binary_nmu_version'};
1379 delete $pkg->{'binary_nmu_changelog'};
1380 log_ta( $pkg, "--merge-packages" );
1381 update_source_info($pkg);
1382 print "$name ($version) is up-to-date now.\n" if $verbose;
1385 check_dep_wait( "--merge-packages", $installed );
1390 my ($package, $name, $version, $installed);
1392 foreach $package (@_) {
1393 $package =~ s,^.*/,,; # strip path
1394 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
1395 $package =~ s/_[\w\d]+\.changes$//; # strip extension
1396 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
1397 ($name,$version) = ($1,$2);
1400 warn "$package: can't extract package name and version ".
1404 $installed->{$name}{'version'} = $version;
1407 check_dep_wait( "--pretend-avail", $installed );
1410 sub check_dep_wait {
1412 my $installed = shift;
1414 # check all packages in state Dep-Wait if dependencies are all
1417 my $db = get_all_source_info();
1418 foreach $name (keys %$db) {
1419 next if $name =~ /^_/;
1420 my $pkg = $db->{$name};
1421 next if $pkg->{'state'} ne "Dep-Wait";
1422 my $deps = $pkg->{'depends'};
1424 print "$name: was in state Dep-Wait, but with empty ",
1426 goto make_needs_build;
1428 my $deplist = parse_deplist($deps);
1432 foreach (keys %$deplist) {
1433 if (!exists $installed->{$_} ||
1434 ($deplist->{$_}->{'rel'} && $deplist->{$_}->{'version'} &&
1435 !version_compare( $installed->{$_}{'version'},
1436 $deplist->{$_}->{'rel'},
1437 $deplist->{$_}->{'version'}))) {
1439 $new_deplist->{$_} = $deplist->{$_};
1442 push( @removed_deps, $_ );
1447 change_state( \$pkg, 'Needs-Build' );
1448 log_ta( $pkg, $action );
1449 delete $pkg->{'builder'};
1450 delete $pkg->{'depends'};
1451 print "$name ($pkg->{'version'}) has all ",
1452 "dependencies available now\n" if $verbose;
1454 update_source_info($pkg);
1456 elsif (@removed_deps) {
1457 $pkg->{'depends'} = build_deplist( $new_deplist );
1458 print "$name ($pkg->{'version'}): some dependencies ",
1459 "(@removed_deps) available now, but not all yet\n"
1461 update_source_info($pkg);
1466 # This function accepts quinn-diff output (either from a file named on
1467 # the command line, or on stdin) and sets the packages named there to
1468 # state 'Needs-Build'.
1469 sub parse_quinn_diff {
1470 my $partial = shift;
1474 my $pkgs = get_all_source_info();
1478 next if !m,^([-\w\d/]*)/ # section
1479 ([-\w\d.+]+)_ # package name
1480 ([\w\d:.~+-]+)\.dsc\s* # version
1481 \[([^:]*): # priority
1482 ([^]]+)\]\s*$,x; # rest of notes
1483 my($section,$name,$version,$priority,$notes) = ($1, $2, $3, $4, $5);
1484 $quinn_pkgs{$name}++;
1485 $section ||= "unknown";
1486 $priority ||= "unknown";
1487 $priority = "unknown" if $priority eq "-";
1488 $priority = "standard" if ($name eq "debian-installer");
1490 my $pkg = $pkgs->{$name};
1492 # Always update section and priority.
1493 if (defined($pkg)) {
1495 $pkg->{'section'} = $section, $change++ if not defined
1496 $pkg->{'section'} or $section ne "unknown";
1497 $pkg->{'priority'} = $priority, $change++ if not defined
1498 $pkg->{'priority'} or $priority ne "unknown";
1501 if (defined($pkg) &&
1502 $pkg->{'state'} =~ /^Dep-Wait/ &&
1503 version_less( $pkg->{'version'}, $version )) {
1504 change_state( \$pkg, 'Dep-Wait' );
1505 $pkg->{'version'} = $version;
1506 delete $pkg->{'binary_nmu_version'};
1507 delete $pkg->{'binary_nmu_changelog'};
1508 log_ta( $pkg, "--merge-quinn" );
1510 print "$name ($version) still waiting for dependencies.\n"
1513 elsif (defined($pkg) &&
1514 $pkg->{'state'} =~ /-Removed$/ &&
1515 version_eq($pkg->{'version'}, $version)) {
1516 # reinstantiate a package that has been removed earlier
1517 # (probably due to a quinn-diff malfunction...)
1518 my $newstate = $pkg->{'state'};
1519 $newstate =~ s/-Removed$//;
1520 change_state( \$pkg, $newstate );
1521 $pkg->{'version'} = $version;
1522 $pkg->{'notes'} = $notes;
1523 log_ta( $pkg, "--merge-quinn" );
1525 print "$name ($version) reinstantiated to $newstate.\n"
1528 elsif (defined($pkg) &&
1529 $pkg->{'state'} eq "Not-For-Us" &&
1530 version_less( $pkg->{'version'}, $version )) {
1531 # for Not-For-Us packages just update the version etc., but
1533 change_state( \$pkg, "Not-For-Us" );
1534 $pkg->{'package'} = $name;
1535 $pkg->{'version'} = $version;
1536 $pkg->{'notes'} = $notes;
1537 delete $pkg->{'builder'};
1538 log_ta( $pkg, "--merge-quinn" );
1540 print "$name ($version) still Not-For-Us.\n" if $verbose;
1542 elsif (!defined($pkg) ||
1543 $pkg->{'state'} ne "Not-For-Us" &&
1544 (version_less( $pkg->{'version'}, $version ) ||
1545 ($pkg->{'state'} eq "Installed" && version_less($pkg->{'installed_version'}, $version)))) {
1547 if (defined( $pkg->{'state'} ) && isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
1548 send_mail( $pkg->{'builder'},
1549 "new version of $name (dist=$distribution)",
1550 "As far as I'm informed, you're currently ".
1551 "building the package $name\n".
1552 "in version $pkg->{'version'}.\n\n".
1553 "Now there's a new source version $version. ".
1554 "If you haven't finished\n".
1555 "compiling $name yet, you can stop it to ".
1556 "save some work.\n".
1557 "Just to inform you...\n".
1558 "(This is an automated message)\n" );
1559 print "$name: new version ($version) while building ".
1560 "$pkg->{'version'} -- sending mail ".
1561 "to builder ($pkg->{'builder'})\n"
1564 change_state( \$pkg, 'Needs-Build' );
1565 $pkg->{'package'} = $name;
1566 $pkg->{'version'} = $version;
1567 $pkg->{'section'} = $section;
1568 $pkg->{'priority'} = $priority;
1569 $pkg->{'notes'} = $notes;
1570 delete $pkg->{'builder'};
1571 delete $pkg->{'binary_nmu_version'};
1572 delete $pkg->{'binary_nmu_changelog'};
1573 log_ta( $pkg, "--merge-quinn" );
1576 print "$name ($version) needs rebuilding now.\n" if $verbose;
1578 elsif (defined($pkg) &&
1579 !version_eq( $pkg->{'version'}, $version ) &&
1580 isin( $pkg->{'state'}, qw(Installed Not-For-Us) )) {
1581 print "$name: skipping because version in db ".
1582 "($pkg->{'version'}) is >> than ".
1583 "what quinn-diff says ($version) ".
1584 "(state is $pkg->{'state'})\n"
1586 $dubious .= "$pkg->{'state'}: ".
1587 "db ${name}_$pkg->{'version'} >> ".
1588 "quinn $version\n" if !$partial;
1590 elsif ($verbose >= 2) {
1591 if ($pkg->{'state'} eq "Not-For-Us") {
1592 print "Skipping $name because State == ".
1593 "$pkg->{'state'}\n";
1595 elsif (!version_less($pkg->{'version'}, $version)) {
1596 print "Skipping $name because version in db ".
1597 "($pkg->{'version'}) is >= than ".
1598 "what quinn-diff says ($version)\n";
1601 update_source_info($pkg) if $change;
1605 send_mail( $conf::db_maint,
1606 "Dubious versions in " . table_name() . " "
1607 . $distribution . " table",
1608 "The following packages have a newer version in the ".
1609 "wanna-build database\n".
1610 "than what quinn-diff says, and this is strange for ".
1612 "It could be caused by a lame mirror, or the version ".
1613 "in the database\n".
1618 # Now re-check the DB for packages in states Needs-Build, Failed,
1619 # Dep-Wait or BD-Uninstallable and remove them if they're not listed
1620 # anymore by quinn-diff.
1623 my $db = get_all_source_info();
1624 foreach $name (keys %$db) {
1625 next if $name =~ /^_/;
1626 my $pkg = $db->{$name};
1627 next if defined $pkg->{'binary_nmu_version'};
1628 next if !isin( $pkg->{'state'},
1629 qw(Needs-Build Building Built Build-Attempted Uploaded Failed Dep-Wait BD-Uninstallable) );
1630 my $virtual_delete = $pkg->{'state'} eq 'Failed';
1632 if (!$quinn_pkgs{$name}) {
1633 change_state( \$pkg, $virtual_delete ?
1634 $pkg->{'state'}."-Removed" :
1636 log_ta( $pkg, "--merge-quinn" );
1637 print "$name ($pkg->{'version'}): ".
1638 ($virtual_delete ? "(virtually) " : "") . "deleted ".
1639 "from database, because not in quinn-diff anymore\n"
1641 if ($virtual_delete) {
1642 update_source_info($pkg);
1644 del_source_info($name);
1652 # for sorting priorities and sections
1654 %prioval = ( required => -5,
1662 'debian-installer' => -199,
1683 localizations => -178,
1684 interpreters => -177,
1709 electronics => -152,
1715 foreach my $i (keys %sectval) {
1716 $sectval{"contrib/$i"} = $sectval{$i}+40;
1717 $sectval{"non-free/$i"} = $sectval{$i}+80;
1719 $sectval{'unknown'} = -165;
1721 %catval = ( "none" => -20,
1722 "uploaded-fixed-pkg" => -19,
1723 "fix-expected" => -18,
1724 "reminder-sent" => -17,
1725 "nmu-offered" => -16,
1729 "compiler-error" => -12 );
1732 sub sort_list_func {
1733 my( $letter, $x, $ax, $bx );
1735 foreach $letter (split( "", $list_order )) {
1736 SWITCH: foreach ($letter) {
1738 $x = $b->{'buildpri'} <=> $a->{'buildpri'};
1739 return $x if $x != 0;
1743 $x = $prioval{$a->{'priority'}} <=> $prioval{$b->{'priority'}};
1744 return $x if $x != 0;
1748 $x = $sectval{$a->{'section'}} <=> $sectval{$b->{'section'}};
1749 return $x if $x != 0;
1753 $x = $a->{'package'} cmp $b->{'package'};
1754 return $x if $x != 0;
1758 $x = $a->{'builder'} cmp $b->{'builder'};
1759 return $x if $x != 0;
1763 $ax = ($a->{'notes'} =~ /^(out-of-date|partial)/) ? 0 :
1764 ($a->{'notes'} =~ /^uncompiled/) ? 2 : 1;
1765 $bx = ($b->{'notes'} =~ /^(out-of-date|partial)/) ? 0 :
1766 ($b->{'notes'} =~ /^uncompiled/) ? 2 : 1;
1768 return $x if $x != 0;
1772 my $ca = defined $a->{'failed_category'} ?
1773 $a->{'failed_category'} : "none";
1774 my $cb = defined $b->{'failed_category'} ?
1775 $b->{'failed_category'} : "none";
1776 $x = $catval{$ca} <=> $catval{$cb};
1777 return $x if $x != 0;
1781 my $pa = $prioval{$a->{'priority'}} >
1782 $prioval{'standard'};
1783 my $pb = $prioval{$b->{'priority'}} >
1784 $prioval{'standard'};
1786 return $x if $x != 0;
1796 my( $name, $pkg, @list );
1801 my $db = get_all_source_info(state => $state, user => $user, category => $category, list_min_age => $list_min_age);
1802 foreach $name (keys %$db) {
1803 next if $name =~ /^_/;
1804 push @list, $db->{$name};
1807 foreach $pkg (sort sort_list_func @list) {
1808 print "$pkg->{'section'}/$pkg->{'package'}_$pkg->{'version'}";
1809 print ": $pkg->{'state'}"
1811 print " by $pkg->{'builder'}"
1812 if $pkg->{'state'} ne "Needs-Build" && $pkg->{'builder'};
1813 print " [$pkg->{'priority'}:$pkg->{'notes'}";
1814 print ":PREV-FAILED"
1815 if $pkg->{'previous_state'} =~ /^Failed/;
1816 print ":bp{" . $pkg->{'buildpri'} . "}"
1817 if defined $pkg->{'buildpri'};
1818 print ":binNMU{" . $pkg->{'binary_nmu_version'} . "}"
1819 if defined $pkg->{'binary_nmu_version'};
1821 print " Reasons for failing:\n",
1823 defined $pkg->{'failed_category'} ? $pkg->{'failed_category'} : "none",
1825 join("\n ",split("\n",$pkg->{'failed'})), "\n"
1826 if $pkg->{'state'} =~ /^Failed/;
1827 print " Dependencies: $pkg->{'depends'}\n"
1828 if $pkg->{'state'} eq "Dep-Wait";
1829 print " Reasons for BD-Uninstallable:\n ",
1830 join("\n ",split("\n",$pkg->{'bd_problem'})), "\n"
1831 if $pkg->{'state'} eq "BD-Uninstallable";
1832 print " Previous state was $pkg->{'previous_state'} until ",
1833 "$pkg->{'state_change'}\n"
1834 if $verbose && $pkg->{'previous_state'};
1835 print " No previous state recorded\n"
1836 if $verbose && !$pkg->{'previous_state'};
1837 print " Previous failing reasons:\n ",
1838 join("\n ",split("\n",$pkg->{'old_failed'})), "\n"
1839 if $verbose && $pkg->{'old_failed'};
1841 $scnt{$pkg->{'state'}}++ if $state eq "all";
1843 if ($state eq "all") {
1844 foreach (sort keys %scnt) {
1845 print "Total $scnt{$_} package(s) in state $_.\n";
1848 print "Total $cnt package(s)\n";
1853 my( $name, $pkg, $key, $dist );
1854 my @firstkeys = qw(package version builder state section priority
1855 installed_version previous_state state_change);
1856 my @dists = $info_all_dists ? keys %conf::distributions : ($distribution);
1858 foreach $name (@_) {
1859 $name =~ s/_.*$//; # strip version
1860 foreach $dist (@dists) {
1861 my $pname = "$name" . ($info_all_dists ? "($dist)" : "");
1863 $pkg = get_readonly_source_info($name);
1864 if (!defined( $pkg )) {
1865 print "$pname: not registered\n";
1870 foreach $key (@firstkeys) {
1871 next if !defined $pkg->{$key};
1872 my $val = $pkg->{$key};
1874 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
1876 my $print_key = $key;
1877 $print_key = 'Package' if ($key eq 'package');
1878 $print_key = 'Version' if ($key eq 'version');
1879 $print_key = 'Builder' if ($key eq 'builder');
1880 $print_key = 'State' if ($key eq 'state');
1881 $print_key = 'Section' if ($key eq 'section');
1882 $print_key = 'Priority' if ($key eq 'priority');
1883 $print_key = 'Installed-Version' if ($key eq 'installed_version');
1884 $print_key = 'Previous-State' if ($key eq 'previous_state');
1885 $print_key = 'State-Change' if ($key eq 'state_change');
1886 printf " %-20s: %s\n", $print_key, $val;
1888 foreach $key (sort keys %$pkg) {
1889 next if isin( $key, @firstkeys );
1890 my $val = $pkg->{$key};
1891 next if !defined($val);
1893 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
1895 my $print_key = $key;
1896 $print_key = 'BD-Problem' if ($key eq 'bd_problem');
1897 $print_key = 'Binary-NMU-Changelog' if ($key eq 'binary_nmu_changelog');
1898 $print_key = 'Binary-NMU-Version' if ($key eq 'binary_nmu_version');
1899 $print_key = 'BuildPri' if ($key eq 'buildpri');
1900 $print_key = 'Depends' if ($key eq 'depends');
1901 $print_key = 'Failed' if ($key eq 'failed');
1902 $print_key = 'Failed-Category' if ($key eq 'failed_category');
1903 $print_key = 'Notes' if ($key eq 'notes');
1904 $print_key = 'Distribution' if ($key eq 'distribution');
1905 $print_key = 'Old-Failed' if ($key eq 'old_failed');
1906 $print_key = 'PermBuildPri' if ($key eq 'permbuildpri');
1907 $print_key = 'Rel' if ($key eq 'rel');
1908 printf " %-20s: %s\n", $print_key, $val;
1914 sub forget_packages {
1915 my( $name, $pkg, $key, $data );
1917 foreach $name (@_) {
1918 $name =~ s/_.*$//; # strip version
1919 $pkg = get_source_info($name);
1920 if (!defined( $pkg )) {
1921 print "$name: not registered\n";
1926 foreach $key (sort keys %$pkg) {
1927 my $val = $pkg->{$key};
1930 $data .= sprintf " %-20s: %s\n", $key, $val;
1932 send_mail( $conf::db_maint,
1933 "$name deleted from DB " . table_name() . " " . $distribution,
1934 "The package '$name' has been deleted from the database ".
1936 "Data registered about the deleted package:\n".
1937 "$data\n" ) if $conf::db_maint;
1938 change_state( \$pkg, 'deleted' );
1939 log_ta( $pkg, "--forget" );
1940 del_source_info($name);
1941 print "$name: deleted from database\n" if $verbose;
1946 $dbh->do("DELETE from " . user_table_name() .
1947 " WHERE distribution = ?", undef, $distribution) or die $dbh->errstr;
1953 print "Reading ASCII database from $file..." if $verbose >= 1;
1954 open( F, "<$file" ) or
1955 die "Can't open database $file: $!\n";
1957 local($/) = ""; # read in paragraph mode
1959 my( %thispkg, $name );
1961 s/\n[ \t]+/\376\377/g; # fix continuation lines
1962 s/\376\377\s*\376\377/\376\377/og;
1964 while( /^(\S+):[ \t]*(.*)[ \t]*$/mg ) {
1965 my ($key, $val) = ($1, $2);
1967 $key =~ tr/A-Z/a-z/;
1968 $val =~ s/\376\377/\n/g;
1969 $thispkg{$key} = $val;
1971 check_entry( \%thispkg );
1973 if (exists($thispkg{'package'})) {
1974 update_source_info(\%thispkg);
1976 elsif(exists($thispkg{'user'})) {
1977 # user in import, username in database.
1978 $dbh->do('INSERT INTO ' . user_table_name() .
1979 ' (username, distribution, last_seen)' .
1980 ' values (?, ?, ?)',
1981 undef, $thispkg{'user'}, $distribution,
1982 $thispkg{'last_seen'})
1983 or die $dbh->errstr;
1987 print "done\n" if $verbose >= 1;
1994 return if $op_mode eq "manual-edit"; # no checks then
1996 # check for required fields
1997 if (exists $pkg->{'user'}) {
2000 if (!exists $pkg->{'package'}) {
2001 print STDERR "Bad entry: ",
2002 join( "\n", map { "$_: $pkg->{$_}" } keys %$pkg ), "\n";
2003 die "Database entry lacks package or username field\n";
2005 # if no State: field, generate one (for old db compat)
2006 if (!exists($pkg->{'state'})) {
2008 exists $pkg->{'failed'} ? 'Failed' : 'Building';
2010 if (!exists $pkg->{'version'} and $pkg->{'state'} ne 'Not-For-Us') {
2011 die "Database entry for $pkg->{'package'} lacks Version: field\n";
2014 die "Bad state $pkg->{'state'} of package $pkg->{Package}\n"
2015 if !isin( $pkg->{'state'},
2016 qw(Needs-Build Building Built Build-Attempted Uploaded Installed Dep-Wait Dep-Wait-Removed
2017 Failed Failed-Removed Not-For-Us BD-Uninstallable
2023 my($name,$pkg,$key);
2025 print "Writing ASCII database to $file..." if $verbose >= 1;
2026 open( F, ">$file" ) or
2027 die "Can't open export $file: $!\n";
2029 my $db = get_all_source_info();
2030 foreach $name (keys %$db) {
2031 next if $name =~ /^_/;
2032 my $pkg = $db->{$name};
2033 foreach $key (keys %{$pkg}) {
2034 my $val = $pkg->{$key};
2035 next if !defined($val);
2038 $val =~ s/^ +$/ ./mg;
2039 print F "$key: $val\n";
2044 print "done\n" if $verbose >= 1;
2050 my $newstate = shift;
2051 my $state = \$pkg->{'state'};
2053 return if defined($$state) and $$state eq $newstate;
2054 $pkg->{'previous_state'} = $$state if defined($$state);
2055 $pkg->{'state_change'} = $curr_date;
2057 if (defined($$state) and $$state eq 'Failed') {
2058 $pkg->{'old_failed'} =
2059 "-"x20 . " $pkg->{'version'} " . "-"x20 . "\n" .
2060 $pkg->{'failed'} . "\n" .
2061 $pkg->{'old_failed'};
2062 delete $pkg->{'failed'};
2063 delete $pkg->{'failed_category'};
2065 if (defined($$state) and $$state eq 'BD-Uninstallable') {
2066 delete $pkg->{'bd_problem'};
2068 $$state = $newstate;
2074 my $dist = $distribution;
2078 $prevstate = $pkg->{'previous_state'};
2079 $str = "$action($dist): $pkg->{'package'}_$pkg->{'version'} ".
2080 "changed from $prevstate to $pkg->{'state'} ".
2081 "by $real_user as $user";
2083 $dbh->do('INSERT INTO ' . transactions_table_name() .
2084 ' (package, distribution, version, action, ' .
2085 ' prevstate, state, real_user, set_user, time) ' .
2086 ' values (?, ?, ?, ?, ?, ?, ?, ?, ?)',
2087 undef, $pkg->{'package'}, $distribution,
2088 $pkg->{'version'}, $action, $prevstate, $pkg->{'state'},
2089 $real_user, $user, 'now()') or die $dbh->errstr;
2091 if (!($prevstate eq 'Failed' && $pkg->{'state'} eq 'Failed')) {
2092 $str .= " (with --override)"
2094 $mail_logs .= "$str\n";
2101 my $subject = shift;
2104 my $from = $conf::db_maint;
2105 my $domain = $conf::buildd_domain;
2107 $from .= "\@$domain" if $from !~ /\@/;
2109 $to .= '@' . $domain if $to !~ /\@/;
2110 $text =~ s/^\.$/../mg;
2111 local $SIG{'PIPE'} = 'IGNORE';
2112 open( PIPE, "| $conf::mailprog -oem $to" )
2113 or die "Can't open pipe to $conf::mailprog: $!\n";
2115 print PIPE "From: $from\n";
2116 print PIPE "Subject: $subject\n\n";
2117 print PIPE "$text\n";
2121 # for parsing input to dep-wait
2127 foreach (split( /\s*,\s*/, $deps )) {
2129 # verification requires > starting prompts, no | crap
2130 if (!/^(\S+)\s*(\(\s*(>(?:[>=])?)\s*(\S+)\s*\))?\s*$/) {
2135 my @alts = split( /\s*\|\s*/, $_ );
2136 # Anything with an | is ignored, as it can be configured on a
2137 # per-buildd basis what will be installed
2138 next if $#alts != 0;
2141 if (!/^(\S+)\s*(\(\s*(>=|=|==|>|>>|<<|<=)\s*(\S+)\s*\))?\s*$/) {
2142 warn( "parse_deplist: bad dependency $_\n" );
2145 my($dep, $rel, $relv) = ($1, $3, $4);
2146 $rel = ">>" if defined($rel) and $rel eq ">";
2147 $result{$dep}->{'package'} = $dep;
2148 if ($rel && $relv) {
2149 $result{$dep}->{'rel'} = $rel;
2150 $result{$dep}->{'version'} = $relv;
2153 return 1 if $verify;
2161 foreach $key (keys %$list) {
2162 $result .= ", " if $result;
2164 $result .= " ($list->{$key}->{'rel'} $list->{$key}->{'version'})"
2165 if $list->{$key}->{'rel'} && $list->{$key}->{'version'};
2170 sub call_edos_depcheck {
2171 my $packagesfile = shift;
2175 return if defined ($conf::distributions{$distribution}{noadw});
2177 # We need to check all of needs-build, as any new upload could make
2178 # something in needs-build have uninstallable deps
2179 # We also check everything in bd-uninstallable, as any new upload could
2180 # make that work again
2181 my %interesting_packages;
2182 my $db = get_all_source_info();
2183 foreach $key (keys %$db) {
2184 my $pkg = $db->{$key};
2185 if (defined $pkg and isin($pkg->{'state'}, qw/Needs-Build BD-Uninstallable/)) {
2186 $interesting_packages{$key} = undef;
2190 #print "I would look at these sources with edos-depcheck:\n";
2191 #print join " ", keys %interesting_packages,"\n";
2193 my $tmpfile_pattern = "/tmp/wanna-build-interesting-sources-$distribution.$$-";
2195 for( $i = 0;; ++$i ) {
2196 $tmpfile = $tmpfile_pattern . $i;
2197 last if ! -e $tmpfile;
2200 open SOURCES, '>', $tmpfile or die "Could not open temporary file $tmpfile\n";
2201 for my $key (keys %interesting_packages) {
2202 my $pkg = $db->{$key};
2203 print SOURCES "Package: $key\n";
2204 print SOURCES "Version: $pkg->{'version'}\n";
2205 print SOURCES "Build-Depends: $srcs->{$key}{'dep'}\n" if $srcs->{$key}{'dep'};
2206 print SOURCES "Build-Conflicts: $srcs->{$key}{'conf'}\n" if $srcs->{$key}{'conf'};
2207 print SOURCES "Architecture: all\n";
2212 if (open(EDOS,"-|","wb-edos-builddebcheck", "-a", $arch, $packagesfile, $tmpfile))
2214 local($/) = ""; # read in paragraph mode
2216 my( $key, $reason ) ;
2218 /^Package:\s*(\S+)$/mi and $key = $1;
2219 /^Failed-Why:(([^\n]|\n ([^\n]|\.))*)$/msi and $reason = $1;
2220 $reason =~ s/^\s*//mg;
2221 $reason ||= 'No reason given by edos-debcheck';
2223 if (exists $interesting_packages{$key}) {
2224 $interesting_packages{$key} = $reason;
2226 #print "TODO: edos reported a package we do not care about now\n" if $verbose;
2231 print "ERROR: Could not run wb-edos-builddebcheck. I am continuing, assuming\n" .
2232 "all packages have installable build-dependencies."
2237 for my $key (keys %interesting_packages) {
2238 my $pkg = $db->{$key};
2240 (defined $interesting_packages{$key} and $pkg->{'state'} eq 'Needs-Build') ||
2241 (not defined $interesting_packages{$key} and $pkg->{'state'} eq 'BD-Uninstallable');
2242 my $problemchange = $interesting_packages{$key} ne $pkg->{'bd_problem'};
2244 if (defined $interesting_packages{$key}) {
2245 change_state( \$pkg, 'BD-Uninstallable' );
2246 $pkg->{'bd_problem'} = $interesting_packages{$key};
2248 change_state( \$pkg, 'Needs-Build' );
2251 if ($problemchange) {
2252 if (defined $interesting_packages{$key}) {
2253 $pkg->{'bd_problem'} = $interesting_packages{$key};
2257 log_ta( $pkg, "--merge-all" );
2258 print "edos-builddebchange changed state of ${key}_$pkg->{'version'} to $pkg->{'state'}\n" if $verbose;
2260 if ($change || $problemchange) {
2261 update_source_info($pkg);
2268 ($prgname = $0) =~ s,^.*/,,;
2270 Usage: $prgname <options...> <package_version...>
2272 -v, --verbose: Verbose execution.
2273 -A arch: Architecture this operation is for.
2274 --take: Take package for building [default operation]
2275 -f, --failed: Record in database that a build failed due to
2276 deficiencies in the package (that aren't fixable without a new
2278 -u, --uploaded: Record in the database that the packages build
2279 correctly and were uploaded.
2280 -n, --no-build: Record in the database that the packages aren't
2281 desired for this architecture and shouldn't appear in listings even
2282 if they're out of date.
2283 --dep-wait: Record in the database that the packages are waiting
2284 for some source dependencies to become available
2285 --binNMU num: Schedule a re-build of the package with unchanged source, but
2286 a new version number (source-version + "+b<num>")
2287 --give-back: Mark a package as ready to build that is in state Building,
2288 Built or Build-Attempted. To give back a package in state Failed, use
2289 --override. This command will actually put the package in state
2290 BD-Uninstallable, until the installability of its Build-Dependencies
2291 were verified. This happens at each call of --merge-all, usually
2293 --merge-quinn: Merge quinn-diff output into database.
2294 --merge-packages: Merge Packages files into database.
2295 --pretend-avail: Pretend that given packages are available now and give
2296 free packages waiting for them
2297 -i SRC_PKG, --info SRC_PKG: Show information for source package
2298 -l STATE, --list=STATE: List all packages in state STATE; can be
2299 combined with -U to restrict to a specific user; STATE can
2301 -m MESSAGE, --message=MESSAGE: Give reason why package failed or
2302 source dependency list
2303 (used with -f, --dep-wait, and --binNMU)
2304 -o, --override: Override another user's lock on a package, i.e.
2305 take it over; a notice mail will be sent to the other user
2306 -U USER, --user=USER: select user name for which listings should
2307 apply, if not given all users are listed.
2308 if -l is missing, set user name to be entered in db; usually
2309 automatically choosen
2310 --import FILE: Import database from a ASCII file FILE
2311 --export FILE: Export database to a ASCII file FILE
2313 The remaining arguments (depending on operation) usually start with
2314 "name_version", the trailer is ignored. This allows to pass the names
2315 of .dsc files, for which file name completion can be used.
2316 --merge-packages and --merge-quinn take Package/quin--diff file names
2317 on the command line or read stdin. --list needs nothing more on the
2318 command line. --info takes source package names (without version).
2323 sub pkg_version_eq {
2325 my $version = shift;
2328 if (defined $pkg->{'binary_nmu_version'}) and
2329 version_compare(binNMU_version($pkg->{'version'},
2330 $pkg->{'binary_nmu_version'}),'=', $version);
2331 return version_compare( $pkg->{'version'}, "=", $version );
2335 return '"' . $arch . $schema_suffix . '".packages';
2338 sub user_table_name {
2339 return '"' . $arch . $schema_suffix . '".users';
2342 sub transactions_table_name {
2343 return '"' . $arch . $schema_suffix . '".transactions';
2346 sub get_readonly_source_info {
2348 my $pkg = $dbh->selectrow_hashref('SELECT * FROM ' .
2349 table_name() . ' WHERE package = ? AND distribution = ?',
2350 undef, $name, $distribution);
2354 sub get_source_info {
2356 my $pkg = $dbh->selectrow_hashref('SELECT * FROM ' .
2357 table_name() . ' WHERE package = ? AND distribution = ?' .
2359 undef, $name, $distribution);
2363 sub get_all_source_info {
2366 my $q = 'SELECT * FROM ' . table_name()
2367 . ' WHERE distribution = ? ';
2368 my @args = ($distribution);
2369 if ($options{state} && uc($options{state}) ne "ALL") {
2370 $q .= ' AND upper(state) = ? ';
2371 push @args, uc($options{state});
2374 if ($options{user}) {
2375 #this basically means "this user, or no user at all":
2376 $q .= ' AND (builder = ? OR upper(state) = ?)';
2377 push @args, $options{user};
2378 push @args, "NEEDS-BUILD";
2381 if ($options{category}) {
2382 $q .= ' AND failed_category <> ? AND upper(state) = ? ';
2383 push @args, $options{category};
2384 push @args, "FAILED";
2387 if ($options{list_min_age} > 0) {
2388 $q .= ' AND age(state_change::timestamp) > ? ';
2389 push @args, $options{list_min_age} . " days";
2392 if ($options{list_min_age} < 0) {
2393 $q .= ' AND age(state_change::timestamp) < ? ';
2394 push @args, -$options{list_min_age} . " days";
2397 my $db = $dbh->selectall_hashref($q, 'package', undef, @args);
2401 sub update_source_info {
2404 my $pkg2 = get_source_info($pkg->{'package'});
2405 if (! defined $pkg2)
2407 add_source_info($pkg);
2410 $dbh->do('UPDATE ' . table_name() . ' SET ' .
2415 'installed_version = ?, ' .
2416 'previous_state = ?, ' .
2417 'state_change = ?, ' .
2421 'old_failed = ?, ' .
2422 'binary_nmu_version = ?, ' .
2423 'binary_nmu_changelog = ?, ' .
2424 'failed_category = ?, ' .
2425 'permbuildpri = ?, ' .
2430 'WHERE package = ? AND distribution = ?',
2436 $pkg->{'installed_version'},
2437 $pkg->{'previous_state'},
2438 $pkg->{'state_change'},
2442 $pkg->{'old_failed'},
2443 $pkg->{'binary_nmu_version'},
2444 $pkg->{'binary_nmu_changelog'},
2445 $pkg->{'failed_category'},
2446 $pkg->{'permbuildpri'},
2450 $pkg->{'bd_problem'},
2452 $distribution) or die $dbh->errstr;
2455 sub add_source_info {
2457 $dbh->do('INSERT INTO ' . table_name() .
2458 ' (package, distribution) values (?, ?)',
2459 undef, $pkg->{'package'}, $distribution) or die $dbh->errstr;
2462 sub del_source_info {
2464 $dbh->do('DELETE FROM ' . table_name() .
2465 ' WHERE package = ? AND distribution = ?',
2466 undef, $name, $distribution) or die $dbh->errstr;
2471 my $user = $dbh->selectrow_hashref('SELECT * FROM ' .
2472 user_table_name() . ' WHERE username = ? AND distribution = ?',
2473 undef, $name, $distribution);
2477 sub update_user_info {
2479 $dbh->do('UPDATE ' . user_table_name() .
2480 ' SET last_seen = now() WHERE username = ?' .
2481 ' AND distribution = ?',
2482 undef, $user, $distribution)
2483 or die $dbh->errstr;
2489 $dbh->do('INSERT INTO ' . user_table_name() .
2490 ' (username, distribution, last_seen)' .
2491 ' values (?, ?, now())',
2492 undef, $user, $distribution)
2493 or die $dbh->errstr;
2498 $dbh->do('LOCK TABLE ' . table_name() .
2499 ' IN EXCLUSIVE MODE', undef) or die $dbh->errstr;