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(0);
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(0);
423 @ARGV = ( $ARGS[3] );
424 my $pkgs = parse_packages(1);
425 @ARGV = ( $ARGS[1] );
427 @ARGV = ( $ARGS[2] );
428 my $srcs = parse_sources(1);
429 call_edos_depcheck( $ARGS[3], $srcs );
433 die "This operation is restricted to admin users\n"
434 if (defined @conf::admin_users and
435 !isin( $real_user, @conf::admin_users));
436 $dbh->do("DELETE from " . table_name() .
437 " WHERE distribution = ?", undef,
441 read_db( $import_from );
445 export_db( $export_to );
449 die "Unexpected operation mode $op_mode\n";
451 if (not -t and $user =~ /-/) {
452 my $userinfo = get_user_info($user);
453 if (!defined $userinfo)
455 add_user_info($user);
459 update_user_info($user);
465 my $newstate = shift;
466 my( $package, $name, $version, $ok, $reason );
468 foreach $package (@_) {
469 $package =~ s,^.*/,,; # strip path
470 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
471 $package =~ s/_[a-zA-Z\d-]+\.changes$//; # strip extension
472 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
473 ($name,$version) = ($1,$2);
476 warn "$package: can't extract package name and version ".
481 if ($op_mode eq "set-building") {
482 add_one_building( $name, $version );
484 elsif ($op_mode eq "set-built") {
485 add_one_built( $name, $version );
487 elsif ($op_mode eq "set-attempted") {
488 add_one_attempted( $name, $version );
490 elsif ($op_mode eq "set-uploaded") {
491 add_one_uploaded( $name, $version );
493 elsif ($op_mode eq "set-failed") {
494 add_one_failed( $name, $version );
496 elsif ($op_mode eq "set-not-for-us") {
497 add_one_notforus( $name, $version );
499 elsif ($op_mode eq "set-needs-build") {
500 add_one_needsbuild( $name, $version );
502 elsif ($op_mode eq "set-dep-wait") {
503 add_one_depwait( $name, $version );
505 elsif ($op_mode eq "set-build-priority") {
506 set_one_buildpri( $name, $version, 'buildpri' );
508 elsif ($op_mode eq "set-permanent-build-priority") {
509 set_one_buildpri( $name, $version, 'permbuildpri' );
511 elsif ($op_mode eq "set-binary-nmu") {
512 set_one_binnmu( $name, $version );
517 sub add_one_building {
523 my $pkg = get_source_info($name);
525 if ($pkg->{'state'} eq "Not-For-Us") {
527 $reason = "not suitable for this architecture";
529 elsif ($pkg->{'state'} =~ /^Dep-Wait/) {
531 $reason = "not all source dependencies available yet";
533 elsif ($pkg->{'state'} =~ /^BD-Uninstallable/) {
535 $reason = "source dependencies are not installable";
537 elsif ($pkg->{'state'} eq "Uploaded" &&
538 (version_lesseq($version, $pkg->{'version'}))) {
540 $reason = "already uploaded by $pkg->{'builder'}";
541 $reason .= " (in newer version $pkg->{'version'})"
542 if !version_eq($pkg, $version);
544 elsif ($pkg->{'state'} eq "Installed" &&
545 version_less($version,$pkg->{'version'})) {
547 print "$name: Warning: newer version $pkg->{'version'} ".
548 "already installed, but overridden.\n";
552 $reason = "newer version $pkg->{'version'} already in ".
553 "archive; doesn't need rebuilding";
554 print "$name: Note: If the following is due to an epoch ",
555 " change, use --override\n";
558 elsif ($pkg->{'state'} eq "Installed" &&
559 pkg_version_eq($pkg,$version)) {
561 $reason = "is up-to-date in the archive; doesn't need rebuilding";
563 elsif ($pkg->{'state'} eq "Needs-Build" &&
564 version_less($version,$pkg->{'version'})) {
566 print "$name: Warning: newer version $pkg->{'version'} ".
567 "needs building, but overridden.";
571 $reason = "newer version $pkg->{'version'} needs building, ".
575 elsif (isin($pkg->{'state'},qw(Building Built Build-Attempted))) {
576 if (version_less($pkg->{'version'},$version)) {
577 print "$name: Warning: Older version $pkg->{'version'} ",
578 "is being built by $pkg->{'builder'}\n";
579 if ($pkg->{'builder'} ne $user) {
580 send_mail( $pkg->{'builder'},
581 "package takeover in newer version",
582 "You are building package '$name' in ".
583 "version $version\n".
584 "(as far as I'm informed).\n".
585 "$user now has taken the newer ".
586 "version $version for building.".
587 "You can abort the build if you like.\n" );
592 print "User $pkg->{'builder'} had already ",
593 "taken the following package,\n",
594 "but overriding this as you request:\n";
595 send_mail( $pkg->{'builder'}, "package takeover",
596 "The package '$name' (version $version) that ".
597 "was taken by you\n".
598 "has been taken over by $user\n" );
600 elsif ($pkg->{'builder'} eq $user) {
601 print "$name: Note: already taken by you.\n";
602 print "$name: ok\n" if $verbose;
607 $reason = "already taken by $pkg->{'builder'}";
608 $reason .= " (in newer version $pkg->{'version'})"
609 if !version_eq($pkg->{'version'}, $version);
613 elsif ($pkg->{'state'} =~ /^Failed/ &&
614 pkg_version_eq($pkg, $version)) {
616 print "The following package previously failed ",
617 "(by $pkg->{'builder'})\n",
618 "but overriding this as you request:\n";
619 send_mail( $pkg->{'builder'}, "failed package takeover",
620 "The package '$name' (version $version) that ".
622 "and has failed previously has been taken over ".
624 if $pkg->{'builder'} ne $user;
628 $reason = "build of $version failed previously:\n ";
629 $reason .= join( "\n ", split( "\n", $pkg->{'failed'} ));
630 $reason .= "\nalso the package doesn't need builing"
631 if $pkg->{'state'} eq 'Failed-Removed';
637 if ($pkg->{'binary_nmu_version'}) {
638 print "$name: Warning: needs binary NMU $pkg->{'binary_nmu_version'}\n" .
639 "$pkg->{'binary_nmu_changelog'}\n";
642 print "$name: Warning: Previous version failed!\n"
643 if $pkg->{'previous_state'} =~ /^Failed/ ||
644 $pkg->{'state'} =~ /^Failed/;
646 change_state( \$pkg, 'Building' );
647 $pkg->{'package'} = $name;
648 $pkg->{'version'} = $version;
649 $pkg->{'builder'} = $user;
650 log_ta( $pkg, "--take" );
651 update_source_info($pkg);
652 print "$name: $ok\n" if $verbose;
655 print "$name: NOT OK!\n $reason\n";
659 sub add_one_attempted {
662 my $pkg = get_source_info($name);
664 if (!defined($pkg)) {
665 print "$name: not registered yet.\n";
669 if ($pkg->{'state'} ne "Building" ) {
670 print "$name: not taken for building (state is $pkg->{'state'}). ",
674 if ($pkg->{'builder'} ne $user) {
675 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
678 elsif ( !pkg_version_eq($pkg, $version) ) {
679 print "$name: version mismatch ".
680 "$(pkg->{'version'} ".
681 "by $pkg->{'builder'})\n";
685 change_state( \$pkg, 'Build-Attempted' );
686 log_ta( $pkg, "--attempted" );
687 update_source_info($pkg);
688 print "$name: registered as uploaded\n" if $verbose;
694 my $pkg = get_source_info($name);
696 if (!defined($pkg)) {
697 print "$name: not registered yet.\n";
701 if ($pkg->{'state'} ne "Building" ) {
702 print "$name: not taken for building (state is $pkg->{'state'}). ",
706 if ($pkg->{'builder'} ne $user) {
707 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
710 elsif ( !pkg_version_eq($pkg, $version) ) {
711 print "$name: version mismatch ".
712 "$(pkg->{'version'} ".
713 "by $pkg->{'builder'})\n";
716 change_state( \$pkg, 'Built' );
717 log_ta( $pkg, "--built" );
718 update_source_info($pkg);
719 print "$name: registered as built\n" if $verbose;
722 sub add_one_uploaded {
725 my $pkg = get_source_info($name);
727 if (!defined($pkg)) {
728 print "$name: not registered yet.\n";
732 if ($pkg->{'state'} eq "Uploaded" &&
733 pkg_version_eq($pkg,$version)) {
734 print "$name: already uploaded\n";
737 if (!isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
738 print "$name: not taken for building (state is $pkg->{'state'}). ",
742 if ($pkg->{'builder'} ne $user) {
743 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
746 # strip epoch -- buildd-uploader used to go based on the filename.
747 # (to remove at some point)
749 ($pkgver = $pkg->{'version'}) =~ s/^\d+://;
750 $version =~ s/^\d+://; # for command line use
751 if ($pkg->{'binary_nmu_version'} ) {
752 my $nmuver = binNMU_version($pkgver, $pkg->{'binary_nmu_version'});
753 if (!version_eq( $nmuver, $version )) {
754 print "$name: version mismatch ($nmuver registered). ",
758 } elsif (!version_eq($pkgver, $version)) {
759 print "$name: version mismatch ($pkg->{'version'} registered). ",
764 change_state( \$pkg, 'Uploaded' );
765 log_ta( $pkg, "--uploaded" );
766 update_source_info($pkg);
767 print "$name: registered as uploaded\n" if $verbose;
774 my $pkg = get_source_info($name);
776 if (!defined($pkg)) {
777 print "$name: not registered yet.\n";
780 $state = $pkg->{'state'};
782 if ($state eq "Not-For-Us") {
783 print "$name: not suitable for this architecture anyway. Skipping.\n";
786 elsif ($state eq "Failed-Removed") {
787 print "$name: failed previously and doesn't need building. Skipping.\n";
790 elsif ($state eq "Installed") {
791 print "$name: Is already installed in archive. Skipping.\n";
794 elsif ($pkg->{'builder'} &&
795 (($user ne $pkg->{'builder'}) &&
796 !($pkg->{'builder'} =~ /^(\w+)-\w+/ && $1 eq $user))) {
797 print "$name: not taken by you, but by ".
798 "$pkg->{'builder'}. Skipping.\n";
801 elsif ( !pkg_version_eq($pkg, $version) ) {
802 print "$name: version mismatch ".
803 "$(pkg->{'version'} ".
804 "by $pkg->{'builder'})\n";
809 if (!$cat && $fail_reason =~ /^\[([^\]]+)\]/) {
811 $cat = $short_category{$cat} if exists $short_category{$cat};
812 if (!isin( $cat, values %short_category )) {
813 print "$name: Warning: unknown category $cat; discarded\n";
816 $fail_reason =~ s/^\[[^\]]+\][ \t]*\n*//;
819 if ($state eq "Needs-Build") {
820 print "$name: Warning: not registered for building previously, ".
821 "but processing anyway.\n";
823 elsif ($state eq "Uploaded") {
824 print "$name: Warning: marked as uploaded previously, ".
825 "but processing anyway.\n";
827 elsif ($state eq "Dep-Wait") {
828 print "$name: Warning: marked as waiting for dependencies, ".
829 "but processing anyway.\n";
831 elsif ($state eq "BD-Uninstallable") {
832 print "$name: Warning: marked as having uninstallable build-dependencies, ".
833 "but processing anyway.\n";
835 elsif ($state eq "Failed") {
836 print "$name: already registered as failed; will append new message\n"
838 print "$name: already registered as failed; changing category\n"
842 if (($cat eq "reminder-sent" || $cat eq "nmu-offered") &&
843 defined $pkg->{'failed_category'} &&
844 $pkg->{'failed_category'} ne $cat) {
845 (my $action = $cat) =~ s/-/ /;
846 $fail_reason .= "\n$short_date: $action";
849 change_state( \$pkg, 'Failed' );
850 $pkg->{'builder'} = $user;
851 $pkg->{'failed'} .= "\n" if $pkg->{'failed'};
852 $pkg->{'failed'} .= $fail_reason;
853 $pkg->{'failed_category'} = $cat if $cat;
854 if (defined $pkg->{'permbuildpri'}) {
855 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
857 delete $pkg->{'buildpri'};
859 log_ta( $pkg, "--failed" );
860 update_source_info($pkg);
861 print "$name: registered as failed\n" if $verbose;
864 sub add_one_notforus {
867 my $pkg = get_source_info($name);
869 if ($pkg->{'state'} eq 'Not-For-Us') {
870 # reset Not-For-Us state in case it's called twice; this is
871 # the only way to get a package out of this state...
872 # There is no really good state in which such packages should
873 # be put :-( So use Failed for now.
874 change_state( \$pkg, 'Failed' );
875 $pkg->{'package'} = $name;
876 $pkg->{'failed'} = "Was Not-For-Us previously";
877 delete $pkg->{'builder'};
878 delete $pkg->{'depends'};
879 log_ta( $pkg, "--no-build(rev)" );
880 print "$name: now not unsuitable anymore\n";
882 send_mail( $conf::notforus_maint,
883 "$name moved out of Not-For-Us state",
884 "The package '$name' has been moved out of the Not-For-Us ".
886 "It should probably also be removed from ".
887 "Packages-arch-specific or\n".
888 "the action was wrong.\n" )
889 if $conf::notforus_maint;
892 change_state( \$pkg, 'Not-For-Us' );
893 $pkg->{'package'} = $name;
894 delete $pkg->{'builder'};
895 delete $pkg->{'depends'};
896 delete $pkg->{'buildpri'};
897 delete $pkg->{'binary_nmu_version'};
898 delete $pkg->{'binary_nmu_changelog'};
899 log_ta( $pkg, "--no-build" );
900 print "$name: registered as unsuitable\n" if $verbose;
902 send_mail( $conf::notforus_maint,
903 "$name set to Not-For-Us",
904 "The package '$name' has been set to state Not-For-Us ".
906 "It should probably also be added to ".
907 "Packages-arch-specific or\n".
908 "the Not-For-Us state is wrong.\n" )
909 if $conf::notforus_maint;
911 update_source_info($pkg);
914 sub add_one_needsbuild {
918 my $pkg = get_source_info($name);
920 if (!defined($pkg)) {
921 print "$name: not registered; can't give back.\n";
924 $state = $pkg->{'state'};
926 if ($state eq "BD-Uninstallable") {
928 print "$name: Forcing uninstallability mark to be removed. This is not permanent and might be reset with the next trigger run\n";
930 change_state( \$pkg, 'Needs-Build' );
931 delete $pkg->{'builder'};
932 delete $pkg->{'depends'};
933 log_ta( $pkg, "--give-back" );
934 update_source_info($pkg);
935 print "$name: given back\n" if $verbose;
939 print "$name: has uninstallable build-dependencies. Skipping\n",
940 " (use --override to clear dependency list and ",
941 "give back anyway)\n";
945 elsif ($state eq "Dep-Wait") {
947 print "$name: Forcing source dependency list to be cleared\n";
950 print "$name: waiting for source dependencies. Skipping\n",
951 " (use --override to clear dependency list and ",
952 "give back anyway)\n";
956 elsif (!isin( $state, qw(Building Built Build-Attempted))) {
957 print "$name: not taken for building (state is $state).";
959 print "\n$name: Forcing give-back\n";
962 print " Skipping.\n";
966 if (defined ($pkg->{'builder'}) && $user ne $pkg->{'builder'} &&
967 !($pkg->{'builder'} =~ /^(\w+)-\w+/ && $1 eq $user) &&
969 print "$name: not taken by you, but by ".
970 "$pkg->{'builder'}. Skipping.\n";
973 if (!pkg_version_eq($pkg, $version)) {
974 print "$name: version mismatch ($pkg->{'version'} registered). ",
978 if ($distribution eq "unstable") {
979 change_state( \$pkg, 'BD-Uninstallable' );
980 $pkg->{'bd_problem'} = "Installability of build dependencies not tested yet";
982 change_state( \$pkg, 'Needs-Build' );
984 $pkg->{'builder'} = undef;
985 $pkg->{'depends'} = undef;
986 log_ta( $pkg, "--give-back" );
987 update_source_info($pkg);
988 print "$name: given back\n" if $verbose;
994 my $pkg = get_source_info($name);
997 if (!defined($pkg)) {
998 print "$name: not registered; can't register for binNMU.\n";
1001 my $db_ver = $pkg->{'version'};
1003 if (!version_eq($db_ver, $version)) {
1004 print "$name: version mismatch ($db_ver registered). ",
1008 $state = $pkg->{'state'};
1010 if (defined $pkg->{'binary_nmu_version'}) {
1011 if ($binNMUver == 0) {
1012 change_state( \$pkg, 'Installed' );
1013 delete $pkg->{'builder'};
1014 delete $pkg->{'depends'};
1015 delete $pkg->{'binary_nmu_version'};
1016 delete $pkg->{'binary_nmu_changelog'};
1017 } elsif ($binNMUver <= $pkg->{'binary_nmu_version'}) {
1018 print "$name: already building binNMU $pkg->{'binary_nmu_version'}\n";
1021 $pkg->{'binary_nmu_version'} = $binNMUver;
1022 $pkg->{'binary_nmu_changelog'} = $fail_reason;
1023 $pkg->{'notes'} = 'out-of-date';
1024 $pkg->{'buildpri'} = $pkg->{'permbuildpri'}
1025 if (defined $pkg->{'permbuildpri'});
1027 log_ta( $pkg, "--binNMU" );
1028 update_source_info($pkg);
1030 } elsif ($binNMUver == 0) {
1031 print "${name}_$version: no scheduled binNMU to cancel.\n";
1035 if ($state ne 'Installed') {
1036 print "${name}_$version: not installed; can't register for binNMU.\n";
1040 my $fullver = binNMU_version($version,$binNMUver);
1041 if ( version_lesseq( $fullver, $pkg->{'installed_version'} ) )
1043 print "$name: binNMU $fullver is not newer than current version $pkg->{'installed_version'}\n";
1047 if ($distribution eq "unstable") {
1048 change_state( \$pkg, 'BD-Uninstallable' );
1049 $pkg->{'bd_problem'} = "Installability of build dependencies not tested yet";
1053 change_state( \$pkg, 'Needs-Build' );
1055 delete $pkg->{'builder'};
1056 delete $pkg->{'depends'};
1057 $pkg->{'binary_nmu_version'} = $binNMUver;
1058 $pkg->{'binary_nmu_changelog'} = $fail_reason;
1059 $pkg->{'notes'} = 'out-of-date';
1060 log_ta( $pkg, "--binNMU" );
1061 update_source_info($pkg);
1062 print "${name}: registered for binNMU $fullver\n" if $verbose;
1065 sub set_one_buildpri {
1067 my $version = shift;
1069 my $pkg = get_source_info($name);
1072 if (!defined($pkg)) {
1073 print "$name: not registered; can't set priority.\n";
1076 $state = $pkg->{'state'};
1078 if ($state eq "Not-For-Us") {
1079 print "$name: not suitable for this architecture. Skipping.\n";
1081 } elsif ($state eq "Failed-Removed") {
1082 print "$name: failed previously and doesn't need building. Skipping.\n";
1085 if (!pkg_version_eq($pkg, $version)) {
1086 print "$name: version mismatch ($pkg->{'version'} registered). ",
1090 if ( $build_priority == 0 ) {
1091 delete $pkg->{'buildpri'}
1092 if $key eq 'permbuildpri' and defined $pkg->{'buildpri'}
1093 and $pkg->{'buildpri'} == $pkg->{$key};
1094 delete $pkg->{$key};
1096 $pkg->{'buildpri'} = $build_priority
1097 if $key eq 'permbuildpri';
1098 $pkg->{$key} = $build_priority;
1100 update_source_info($pkg);
1101 print "$name: set to build priority $build_priority\n" if $verbose;
1104 sub add_one_depwait {
1106 my $version = shift;
1108 my $pkg = get_source_info($name);
1110 if (!defined($pkg)) {
1111 print "$name: not registered yet.\n";
1114 $state = $pkg->{'state'};
1116 if ($state eq "Dep-Wait") {
1117 print "$name: merging with previously registered dependencies\n";
1120 if (isin( $state, qw(Needs-Build Failed BD-Uninstallable))) {
1121 print "$name: Warning: not registered for building previously, ".
1122 "but processing anyway.\n";
1124 elsif ($state eq "Not-For-Us") {
1125 print "$name: not suitable for this architecture anyway. Skipping.\n";
1128 elsif ($state eq "Failed-Removed") {
1129 print "$name: failed previously and doesn't need building. Skipping.\n";
1132 elsif ($state eq "Installed") {
1133 print "$name: Is already installed in archive. Skipping.\n";
1136 elsif ($state eq "Uploaded") {
1137 print "$name: Is already uploaded. Skipping.\n";
1140 elsif ($pkg->{'builder'} &&
1141 $user ne $pkg->{'builder'}) {
1142 print "$name: not taken by you, but by ".
1143 "$pkg->{'builder'}. Skipping.\n";
1146 elsif ( !pkg_version_eq($pkg,$version)) {
1147 print "$name: version mismatch ".
1148 "($pkg->{'version'} ".
1149 "by $pkg->{'builder'})\n";
1152 elsif ($fail_reason =~ /^\s*$/ ||
1153 !parse_deplist( $fail_reason, 1 )) {
1154 print "$name: Bad dependency list\n";
1157 change_state( \$pkg, 'Dep-Wait' );
1158 $pkg->{'builder'} = $user;
1159 if (defined $pkg->{'permbuildpri'}) {
1160 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
1162 delete $pkg->{'buildpri'};
1164 my $deplist = parse_deplist( $pkg->{'depends'} );
1165 my $new_deplist = parse_deplist( $fail_reason );
1166 # add new dependencies, maybe overwriting old entries
1167 foreach (keys %$new_deplist) {
1168 $deplist->{$_} = $new_deplist->{$_};
1170 $pkg->{'depends'} = build_deplist($deplist);
1171 log_ta( $pkg, "--dep-wait" );
1172 update_source_info($pkg);
1173 print "$name: registered as waiting for dependencies\n" if $verbose;
1183 my $db = get_all_source_info();
1185 local($/) = ""; # read in paragraph mode
1187 my( $version, $arch, $section, $priority, $builddep, $buildconf, $binaries );
1189 /^Package:\s*(\S+)$/mi and $name = $1;
1190 /^Version:\s*(\S+)$/mi and $version = $1;
1191 /^Architecture:\s*(\S+)$/mi and $arch = $1;
1192 /^Section:\s*(\S+)$/mi and $section = $1;
1193 /^Priority:\s*(\S+)$/mi and $priority = $1;
1194 /^Build-Depends:\s*(.*)$/mi and $builddep = $1;
1195 /^Build-Conflicts:\s*(.*)$/mi and $buildconf = $1;
1196 /^Binary:\s*(.*)$/mi and $binaries = $1;
1198 next if (defined $srcver{$name} and version_less( $version, $srcver{$name} ));
1199 $srcver{$name} = $version;
1201 $pkgs{$name}{'ver'} = $version;
1202 $pkgs{$name}{'bin'} = $binaries;
1203 $pkgs{$name}{'dep'} = $builddep;
1204 $pkgs{$name}{'conf'} = $buildconf;
1205 my $pkg = $db->{$name};
1210 if ($arch eq "all" && !version_less( $version, $pkg->{'version'} )) {
1211 # package is now Arch: all, delete it from db
1212 change_state( \$pkg, 'deleted' );
1213 log_ta( $pkg, "--merge-sources" );
1214 print "$name ($pkg->{'version'}): deleted ".
1215 "from database, because now Arch: all\n"
1217 del_source_info($name);
1218 delete $db->{$name};
1222 # The "Version" should always be the source version --
1223 # not a possible binNMU version number.
1224 $pkg->{'version'} = $version, $change++
1225 if ($pkg->{'state'} eq 'Installed' and
1226 !version_eq( $pkg->{'version'}, $version));
1227 # Always update priority and section, if available
1228 $pkg->{'priority'} = $priority, $change++
1229 if defined $priority and (not defined($pkg->{'priority'}) or $pkg->{'priority'} ne $priority);
1231 $pkg->{'section'} = $section, $change++
1232 if defined $section and (not defined($pkg->{'section'}) or $pkg->{'section'} ne $section);
1234 update_source_info($pkg) if $change;
1237 # Now that we only have the latest source version, build the list
1238 # of binary packages from the Sources point of view
1239 foreach $name (keys %pkgs) {
1240 foreach my $bin (split( /\s*,\s*/, $pkgs{$name}{'bin'} ) ) {
1241 $merge_binsrc{$bin} = $name;
1244 # remove installed packages that no longer have source available
1245 # or binaries installed
1246 foreach $name (keys %$db) {
1247 next if $name =~ /^_/;
1248 my $pkg = $db->{$name};
1249 if (not defined($pkgs{$name})) {
1250 change_state( \$pkg, 'deleted' );
1251 log_ta( $pkg, "--merge-sources" );
1252 print "$name ($pkg->{'version'}): ".
1253 "deleted from database, because ".
1254 "not in Sources anymore\n"
1256 del_source_info($name);
1257 delete $db->{$name};
1259 next if !isin( $pkg->{'state'}, qw(Installed) );
1260 if ($full && not defined $merge_srcvers{$name}) {
1261 change_state( \$pkg, 'deleted' );
1262 log_ta( $pkg, "--merge-sources" );
1263 print "$name ($pkg->{'version'}): ".
1264 "deleted from database, because ".
1265 "binaries don't exist anymore\n"
1267 del_source_info($name);
1268 delete $db->{$name};
1269 } elsif ($full && version_less( $merge_srcvers{$name}, $pkg->{'version'})) {
1270 print "$name ($pkg->{'version'}): ".
1271 "package is Installed but binaries are from ".
1272 $merge_srcvers{$name}. "\n"
1280 # This function looks through a Packages file and sets the state of
1281 # packages to 'Installed'
1282 sub parse_packages {
1283 my depwait_only = shift;
1286 my $pkgs = get_all_source_info();
1287 local($/) = ""; # read in paragraph mode
1289 my( $name, $version, $depends, $source, $sourcev, $architecture, $provides, $binaryv, $binnmu );
1291 /^Package:\s*(\S+)$/mi and $name = $1;
1292 /^Version:\s*(\S+)$/mi and $version = $1;
1293 /^Depends:\s*(.*)$/mi and $depends = $1;
1294 /^Source:\s*(\S+)(\s*\((\S+)\))?$/mi and ($source,$sourcev) = ($1, $3);
1295 /^Architecture:\s*(\S+)$/mi and $architecture = $1;
1296 /^Provides:\s*(.*)$/mi and $provides = $1;
1297 next if !$name || !$version;
1298 next if ($arch ne $architecture and $architecture ne "all");
1299 next if (defined ($installed->{$name}) and $installed->{$name}{'version'} ne "" and
1300 version_lesseq( $version, $installed->{$name}{'version'} ));
1301 $installed->{$name}{'version'} = $version;
1302 next if $depwait_only;
1303 $installed->{$name}{'depends'} = $depends;
1304 $installed->{$name}{'all'} = 1 if $architecture eq "all";
1305 undef $installed->{$name}{'Provider'};
1306 $installed->{$name}{'Source'} = $source ? $source : $name;
1308 foreach (split( /\s*,\s*/, $provides )) {
1309 if (not defined ($installed->{$_})) {
1310 $installed->{$_}{'version'} = "";
1311 $installed->{$_}{'Provider'} = $name;
1315 if ( $version =~ /\+b(\d+)$/ ) {
1318 $version = $sourcev if $sourcev;
1319 $binaryv = $version;
1320 $binaryv =~ s/\+b\d+$//;
1321 $installed->{$name}{'Sourcev'} = $sourcev ? $sourcev : $binaryv;
1322 $binaryv .= "+b$binnmu" if defined($binnmu);
1324 next if $architecture ne $arch;
1325 $name = $source if $source;
1326 next if defined($merge_srcvers{$name}) and $merge_srcvers{$name} eq $version;
1327 $merge_srcvers{$name} = $version;
1329 my $pkg = $pkgs->{$name};
1332 if (isin( $pkg->{'state'}, qw(Not-For-Us)) ||
1333 (isin($pkg->{'state'}, qw(Installed)) &&
1334 version_lesseq($binaryv, $pkg->{'installed_version'}))) {
1335 print "Skipping $name because State == $pkg->{'state'}\n"
1339 if ($pkg->{'binary_nmu_version'} ) {
1340 my $nmuver = binNMU_version($pkg->{'version'}, $pkg->{'binary_nmu_version'});
1341 if (version_less( $binaryv, $nmuver )) {
1342 print "Skipping $name ($version) because have newer ".
1343 "version ($nmuver) in db.\n"
1347 } elsif (version_less($version, $pkg->{'version'})) {
1348 print "Skipping $name ($version) because have newer ".
1349 "version ($pkg->{'version'}) in db.\n"
1354 if (!pkg_version_eq($pkg, $version) &&
1355 $pkg->{'state'} ne "Installed") {
1356 warn "Warning: $name: newer version than expected appeared ".
1357 "in archive ($version vs. $pkg->{'version'})\n";
1358 delete $pkg->{'builder'};
1361 if (!isin( $pkg->{'state'}, qw(Uploaded) )) {
1362 warn "Warning: Package $name was not in uploaded state ".
1363 "before (but in '$pkg->{'state'}').\n";
1364 delete $pkg->{'builder'};
1365 delete $pkg->{'depends'};
1369 $pkg->{'version'} = $version;
1372 change_state( \$pkg, 'Installed' );
1373 $pkg->{'package'} = $name;
1374 $pkg->{'installed_version'} = $binaryv;
1375 if (defined $pkg->{'permbuildpri'}) {
1376 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
1378 delete $pkg->{'buildpri'};
1380 $pkg->{'version'} = $version
1381 if version_less( $pkg->{'version'}, $version);
1382 delete $pkg->{'binary_nmu_version'};
1383 delete $pkg->{'binary_nmu_changelog'};
1384 log_ta( $pkg, "--merge-packages" );
1385 update_source_info($pkg);
1386 print "$name ($version) is up-to-date now.\n" if $verbose;
1389 check_dep_wait( "--merge-packages", $installed );
1394 my ($package, $name, $version, $installed);
1396 foreach $package (@_) {
1397 $package =~ s,^.*/,,; # strip path
1398 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
1399 $package =~ s/_[\w\d]+\.changes$//; # strip extension
1400 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
1401 ($name,$version) = ($1,$2);
1404 warn "$package: can't extract package name and version ".
1408 $installed->{$name}{'version'} = $version;
1411 check_dep_wait( "--pretend-avail", $installed );
1414 sub check_dep_wait {
1416 my $installed = shift;
1418 # check all packages in state Dep-Wait if dependencies are all
1421 my $db = get_all_source_info();
1422 foreach $name (keys %$db) {
1423 next if $name =~ /^_/;
1424 my $pkg = $db->{$name};
1425 next if $pkg->{'state'} ne "Dep-Wait";
1426 my $deps = $pkg->{'depends'};
1428 print "$name: was in state Dep-Wait, but with empty ",
1430 goto make_needs_build;
1432 my $deplist = parse_deplist($deps);
1436 foreach (keys %$deplist) {
1437 if (!exists $installed->{$_} ||
1438 ($deplist->{$_}->{'rel'} && $deplist->{$_}->{'version'} &&
1439 !version_compare( $installed->{$_}{'version'},
1440 $deplist->{$_}->{'rel'},
1441 $deplist->{$_}->{'version'}))) {
1443 $new_deplist->{$_} = $deplist->{$_};
1446 push( @removed_deps, $_ );
1451 change_state( \$pkg, 'Needs-Build' );
1452 log_ta( $pkg, $action );
1453 delete $pkg->{'builder'};
1454 delete $pkg->{'depends'};
1455 print "$name ($pkg->{'version'}) has all ",
1456 "dependencies available now\n" if $verbose;
1458 update_source_info($pkg);
1460 elsif (@removed_deps) {
1461 $pkg->{'depends'} = build_deplist( $new_deplist );
1462 print "$name ($pkg->{'version'}): some dependencies ",
1463 "(@removed_deps) available now, but not all yet\n"
1465 update_source_info($pkg);
1470 # This function accepts quinn-diff output (either from a file named on
1471 # the command line, or on stdin) and sets the packages named there to
1472 # state 'Needs-Build'.
1473 sub parse_quinn_diff {
1474 my $partial = shift;
1478 my $pkgs = get_all_source_info();
1482 next if !m,^([-\w\d/]*)/ # section
1483 ([-\w\d.+]+)_ # package name
1484 ([\w\d:.~+-]+)\.dsc\s* # version
1485 \[([^:]*): # priority
1486 ([^]]+)\]\s*$,x; # rest of notes
1487 my($section,$name,$version,$priority,$notes) = ($1, $2, $3, $4, $5);
1488 $quinn_pkgs{$name}++;
1489 $section ||= "unknown";
1490 $priority ||= "unknown";
1491 $priority = "unknown" if $priority eq "-";
1492 $priority = "standard" if ($name eq "debian-installer");
1494 my $pkg = $pkgs->{$name};
1496 # Always update section and priority.
1497 if (defined($pkg)) {
1499 $pkg->{'section'} = $section, $change++ if not defined
1500 $pkg->{'section'} or $section ne "unknown";
1501 $pkg->{'priority'} = $priority, $change++ if not defined
1502 $pkg->{'priority'} or $priority ne "unknown";
1505 if (defined($pkg) &&
1506 $pkg->{'state'} =~ /^Dep-Wait/ &&
1507 version_less( $pkg->{'version'}, $version )) {
1508 change_state( \$pkg, 'Dep-Wait' );
1509 $pkg->{'version'} = $version;
1510 delete $pkg->{'binary_nmu_version'};
1511 delete $pkg->{'binary_nmu_changelog'};
1512 log_ta( $pkg, "--merge-quinn" );
1514 print "$name ($version) still waiting for dependencies.\n"
1517 elsif (defined($pkg) &&
1518 $pkg->{'state'} =~ /-Removed$/ &&
1519 version_eq($pkg->{'version'}, $version)) {
1520 # reinstantiate a package that has been removed earlier
1521 # (probably due to a quinn-diff malfunction...)
1522 my $newstate = $pkg->{'state'};
1523 $newstate =~ s/-Removed$//;
1524 change_state( \$pkg, $newstate );
1525 $pkg->{'version'} = $version;
1526 $pkg->{'notes'} = $notes;
1527 log_ta( $pkg, "--merge-quinn" );
1529 print "$name ($version) reinstantiated to $newstate.\n"
1532 elsif (defined($pkg) &&
1533 $pkg->{'state'} eq "Not-For-Us" &&
1534 version_less( $pkg->{'version'}, $version )) {
1535 # for Not-For-Us packages just update the version etc., but
1537 change_state( \$pkg, "Not-For-Us" );
1538 $pkg->{'package'} = $name;
1539 $pkg->{'version'} = $version;
1540 $pkg->{'notes'} = $notes;
1541 delete $pkg->{'builder'};
1542 log_ta( $pkg, "--merge-quinn" );
1544 print "$name ($version) still Not-For-Us.\n" if $verbose;
1546 elsif (!defined($pkg) ||
1547 $pkg->{'state'} ne "Not-For-Us" &&
1548 (version_less( $pkg->{'version'}, $version ) ||
1549 ($pkg->{'state'} eq "Installed" && version_less($pkg->{'installed_version'}, $version)))) {
1551 if (defined( $pkg->{'state'} ) && isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
1552 send_mail( $pkg->{'builder'},
1553 "new version of $name (dist=$distribution)",
1554 "As far as I'm informed, you're currently ".
1555 "building the package $name\n".
1556 "in version $pkg->{'version'}.\n\n".
1557 "Now there's a new source version $version. ".
1558 "If you haven't finished\n".
1559 "compiling $name yet, you can stop it to ".
1560 "save some work.\n".
1561 "Just to inform you...\n".
1562 "(This is an automated message)\n" );
1563 print "$name: new version ($version) while building ".
1564 "$pkg->{'version'} -- sending mail ".
1565 "to builder ($pkg->{'builder'})\n"
1568 change_state( \$pkg, 'Needs-Build' );
1569 $pkg->{'package'} = $name;
1570 $pkg->{'version'} = $version;
1571 $pkg->{'section'} = $section;
1572 $pkg->{'priority'} = $priority;
1573 $pkg->{'notes'} = $notes;
1574 delete $pkg->{'builder'};
1575 delete $pkg->{'binary_nmu_version'};
1576 delete $pkg->{'binary_nmu_changelog'};
1577 log_ta( $pkg, "--merge-quinn" );
1580 print "$name ($version) needs rebuilding now.\n" if $verbose;
1582 elsif (defined($pkg) &&
1583 !version_eq( $pkg->{'version'}, $version ) &&
1584 isin( $pkg->{'state'}, qw(Installed Not-For-Us) )) {
1585 print "$name: skipping because version in db ".
1586 "($pkg->{'version'}) is >> than ".
1587 "what quinn-diff says ($version) ".
1588 "(state is $pkg->{'state'})\n"
1590 $dubious .= "$pkg->{'state'}: ".
1591 "db ${name}_$pkg->{'version'} >> ".
1592 "quinn $version\n" if !$partial;
1594 elsif ($verbose >= 2) {
1595 if ($pkg->{'state'} eq "Not-For-Us") {
1596 print "Skipping $name because State == ".
1597 "$pkg->{'state'}\n";
1599 elsif (!version_less($pkg->{'version'}, $version)) {
1600 print "Skipping $name because version in db ".
1601 "($pkg->{'version'}) is >= than ".
1602 "what quinn-diff says ($version)\n";
1605 update_source_info($pkg) if $change;
1609 send_mail( $conf::db_maint,
1610 "Dubious versions in " . table_name() . " "
1611 . $distribution . " table",
1612 "The following packages have a newer version in the ".
1613 "wanna-build database\n".
1614 "than what quinn-diff says, and this is strange for ".
1616 "It could be caused by a lame mirror, or the version ".
1617 "in the database\n".
1622 # Now re-check the DB for packages in states Needs-Build, Failed,
1623 # Dep-Wait or BD-Uninstallable and remove them if they're not listed
1624 # anymore by quinn-diff.
1627 my $db = get_all_source_info();
1628 foreach $name (keys %$db) {
1629 next if $name =~ /^_/;
1630 my $pkg = $db->{$name};
1631 next if defined $pkg->{'binary_nmu_version'};
1632 next if !isin( $pkg->{'state'},
1633 qw(Needs-Build Building Built Build-Attempted Uploaded Failed Dep-Wait BD-Uninstallable) );
1634 my $virtual_delete = $pkg->{'state'} eq 'Failed';
1636 if (!$quinn_pkgs{$name}) {
1637 change_state( \$pkg, $virtual_delete ?
1638 $pkg->{'state'}."-Removed" :
1640 log_ta( $pkg, "--merge-quinn" );
1641 print "$name ($pkg->{'version'}): ".
1642 ($virtual_delete ? "(virtually) " : "") . "deleted ".
1643 "from database, because not in quinn-diff anymore\n"
1645 if ($virtual_delete) {
1646 update_source_info($pkg);
1648 del_source_info($name);
1656 # for sorting priorities and sections
1658 %prioval = ( required => -5,
1666 'debian-installer' => -199,
1687 localizations => -178,
1688 interpreters => -177,
1713 electronics => -152,
1719 foreach my $i (keys %sectval) {
1720 $sectval{"contrib/$i"} = $sectval{$i}+40;
1721 $sectval{"non-free/$i"} = $sectval{$i}+80;
1723 $sectval{'unknown'} = -165;
1725 %catval = ( "none" => -20,
1726 "uploaded-fixed-pkg" => -19,
1727 "fix-expected" => -18,
1728 "reminder-sent" => -17,
1729 "nmu-offered" => -16,
1733 "compiler-error" => -12 );
1736 sub sort_list_func {
1737 my( $letter, $x, $ax, $bx );
1739 foreach $letter (split( "", $list_order )) {
1740 SWITCH: foreach ($letter) {
1742 $x = $b->{'buildpri'} <=> $a->{'buildpri'};
1743 return $x if $x != 0;
1747 $x = $prioval{$a->{'priority'}} <=> $prioval{$b->{'priority'}};
1748 return $x if $x != 0;
1752 $x = $sectval{$a->{'section'}} <=> $sectval{$b->{'section'}};
1753 return $x if $x != 0;
1757 $x = $a->{'package'} cmp $b->{'package'};
1758 return $x if $x != 0;
1762 $x = $a->{'builder'} cmp $b->{'builder'};
1763 return $x if $x != 0;
1767 $ax = ($a->{'notes'} =~ /^(out-of-date|partial)/) ? 0 :
1768 ($a->{'notes'} =~ /^uncompiled/) ? 2 : 1;
1769 $bx = ($b->{'notes'} =~ /^(out-of-date|partial)/) ? 0 :
1770 ($b->{'notes'} =~ /^uncompiled/) ? 2 : 1;
1772 return $x if $x != 0;
1776 my $ca = defined $a->{'failed_category'} ?
1777 $a->{'failed_category'} : "none";
1778 my $cb = defined $b->{'failed_category'} ?
1779 $b->{'failed_category'} : "none";
1780 $x = $catval{$ca} <=> $catval{$cb};
1781 return $x if $x != 0;
1785 my $pa = $prioval{$a->{'priority'}} >
1786 $prioval{'standard'};
1787 my $pb = $prioval{$b->{'priority'}} >
1788 $prioval{'standard'};
1790 return $x if $x != 0;
1800 my( $name, $pkg, @list );
1805 my $db = get_all_source_info(state => $state, user => $user, category => $category, list_min_age => $list_min_age);
1806 foreach $name (keys %$db) {
1807 next if $name =~ /^_/;
1808 push @list, $db->{$name};
1811 foreach $pkg (sort sort_list_func @list) {
1812 print "$pkg->{'section'}/$pkg->{'package'}_$pkg->{'version'}";
1813 print ": $pkg->{'state'}"
1815 print " by $pkg->{'builder'}"
1816 if $pkg->{'state'} ne "Needs-Build" && $pkg->{'builder'};
1817 print " [$pkg->{'priority'}:$pkg->{'notes'}";
1818 print ":PREV-FAILED"
1819 if $pkg->{'previous_state'} =~ /^Failed/;
1820 print ":bp{" . $pkg->{'buildpri'} . "}"
1821 if defined $pkg->{'buildpri'};
1822 print ":binNMU{" . $pkg->{'binary_nmu_version'} . "}"
1823 if defined $pkg->{'binary_nmu_version'};
1825 print " Reasons for failing:\n",
1827 defined $pkg->{'failed_category'} ? $pkg->{'failed_category'} : "none",
1829 join("\n ",split("\n",$pkg->{'failed'})), "\n"
1830 if $pkg->{'state'} =~ /^Failed/;
1831 print " Dependencies: $pkg->{'depends'}\n"
1832 if $pkg->{'state'} eq "Dep-Wait";
1833 print " Reasons for BD-Uninstallable:\n ",
1834 join("\n ",split("\n",$pkg->{'bd_problem'})), "\n"
1835 if $pkg->{'state'} eq "BD-Uninstallable";
1836 print " Previous state was $pkg->{'previous_state'} until ",
1837 "$pkg->{'state_change'}\n"
1838 if $verbose && $pkg->{'previous_state'};
1839 print " No previous state recorded\n"
1840 if $verbose && !$pkg->{'previous_state'};
1841 print " Previous failing reasons:\n ",
1842 join("\n ",split("\n",$pkg->{'old_failed'})), "\n"
1843 if $verbose && $pkg->{'old_failed'};
1845 $scnt{$pkg->{'state'}}++ if $state eq "all";
1847 if ($state eq "all") {
1848 foreach (sort keys %scnt) {
1849 print "Total $scnt{$_} package(s) in state $_.\n";
1852 print "Total $cnt package(s)\n";
1857 my( $name, $pkg, $key, $dist );
1858 my @firstkeys = qw(package version builder state section priority
1859 installed_version previous_state state_change);
1860 my @dists = $info_all_dists ? keys %conf::distributions : ($distribution);
1862 foreach $name (@_) {
1863 $name =~ s/_.*$//; # strip version
1864 foreach $dist (@dists) {
1865 my $pname = "$name" . ($info_all_dists ? "($dist)" : "");
1867 $pkg = get_readonly_source_info($name);
1868 if (!defined( $pkg )) {
1869 print "$pname: not registered\n";
1874 foreach $key (@firstkeys) {
1875 next if !defined $pkg->{$key};
1876 my $val = $pkg->{$key};
1878 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
1880 my $print_key = $key;
1881 $print_key = 'Package' if ($key eq 'package');
1882 $print_key = 'Version' if ($key eq 'version');
1883 $print_key = 'Builder' if ($key eq 'builder');
1884 $print_key = 'State' if ($key eq 'state');
1885 $print_key = 'Section' if ($key eq 'section');
1886 $print_key = 'Priority' if ($key eq 'priority');
1887 $print_key = 'Installed-Version' if ($key eq 'installed_version');
1888 $print_key = 'Previous-State' if ($key eq 'previous_state');
1889 $print_key = 'State-Change' if ($key eq 'state_change');
1890 printf " %-20s: %s\n", $print_key, $val;
1892 foreach $key (sort keys %$pkg) {
1893 next if isin( $key, @firstkeys );
1894 my $val = $pkg->{$key};
1895 next if !defined($val);
1897 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
1899 my $print_key = $key;
1900 $print_key = 'BD-Problem' if ($key eq 'bd_problem');
1901 $print_key = 'Binary-NMU-Changelog' if ($key eq 'binary_nmu_changelog');
1902 $print_key = 'Binary-NMU-Version' if ($key eq 'binary_nmu_version');
1903 $print_key = 'BuildPri' if ($key eq 'buildpri');
1904 $print_key = 'Depends' if ($key eq 'depends');
1905 $print_key = 'Failed' if ($key eq 'failed');
1906 $print_key = 'Failed-Category' if ($key eq 'failed_category');
1907 $print_key = 'Notes' if ($key eq 'notes');
1908 $print_key = 'Distribution' if ($key eq 'distribution');
1909 $print_key = 'Old-Failed' if ($key eq 'old_failed');
1910 $print_key = 'PermBuildPri' if ($key eq 'permbuildpri');
1911 $print_key = 'Rel' if ($key eq 'rel');
1912 printf " %-20s: %s\n", $print_key, $val;
1918 sub forget_packages {
1919 my( $name, $pkg, $key, $data );
1921 foreach $name (@_) {
1922 $name =~ s/_.*$//; # strip version
1923 $pkg = get_source_info($name);
1924 if (!defined( $pkg )) {
1925 print "$name: not registered\n";
1930 foreach $key (sort keys %$pkg) {
1931 my $val = $pkg->{$key};
1934 $data .= sprintf " %-20s: %s\n", $key, $val;
1936 send_mail( $conf::db_maint,
1937 "$name deleted from DB " . table_name() . " " . $distribution,
1938 "The package '$name' has been deleted from the database ".
1940 "Data registered about the deleted package:\n".
1941 "$data\n" ) if $conf::db_maint;
1942 change_state( \$pkg, 'deleted' );
1943 log_ta( $pkg, "--forget" );
1944 del_source_info($name);
1945 print "$name: deleted from database\n" if $verbose;
1950 $dbh->do("DELETE from " . user_table_name() .
1951 " WHERE distribution = ?", undef, $distribution) or die $dbh->errstr;
1957 print "Reading ASCII database from $file..." if $verbose >= 1;
1958 open( F, "<$file" ) or
1959 die "Can't open database $file: $!\n";
1961 local($/) = ""; # read in paragraph mode
1963 my( %thispkg, $name );
1965 s/\n[ \t]+/\376\377/g; # fix continuation lines
1966 s/\376\377\s*\376\377/\376\377/og;
1968 while( /^(\S+):[ \t]*(.*)[ \t]*$/mg ) {
1969 my ($key, $val) = ($1, $2);
1971 $key =~ tr/A-Z/a-z/;
1972 $val =~ s/\376\377/\n/g;
1973 $thispkg{$key} = $val;
1975 check_entry( \%thispkg );
1977 if (exists($thispkg{'package'})) {
1978 update_source_info(\%thispkg);
1980 elsif(exists($thispkg{'user'})) {
1981 # user in import, username in database.
1982 $dbh->do('INSERT INTO ' . user_table_name() .
1983 ' (username, distribution, last_seen)' .
1984 ' values (?, ?, ?)',
1985 undef, $thispkg{'user'}, $distribution,
1986 $thispkg{'last_seen'})
1987 or die $dbh->errstr;
1991 print "done\n" if $verbose >= 1;
1998 return if $op_mode eq "manual-edit"; # no checks then
2000 # check for required fields
2001 if (exists $pkg->{'user'}) {
2004 if (!exists $pkg->{'package'}) {
2005 print STDERR "Bad entry: ",
2006 join( "\n", map { "$_: $pkg->{$_}" } keys %$pkg ), "\n";
2007 die "Database entry lacks package or username field\n";
2009 # if no State: field, generate one (for old db compat)
2010 if (!exists($pkg->{'state'})) {
2012 exists $pkg->{'failed'} ? 'Failed' : 'Building';
2014 if (!exists $pkg->{'version'} and $pkg->{'state'} ne 'Not-For-Us') {
2015 die "Database entry for $pkg->{'package'} lacks Version: field\n";
2018 die "Bad state $pkg->{'state'} of package $pkg->{Package}\n"
2019 if !isin( $pkg->{'state'},
2020 qw(Needs-Build Building Built Build-Attempted Uploaded Installed Dep-Wait Dep-Wait-Removed
2021 Failed Failed-Removed Not-For-Us BD-Uninstallable
2027 my($name,$pkg,$key);
2029 print "Writing ASCII database to $file..." if $verbose >= 1;
2030 open( F, ">$file" ) or
2031 die "Can't open export $file: $!\n";
2033 my $db = get_all_source_info();
2034 foreach $name (keys %$db) {
2035 next if $name =~ /^_/;
2036 my $pkg = $db->{$name};
2037 foreach $key (keys %{$pkg}) {
2038 my $val = $pkg->{$key};
2039 next if !defined($val);
2042 $val =~ s/^ +$/ ./mg;
2043 print F "$key: $val\n";
2048 print "done\n" if $verbose >= 1;
2054 my $newstate = shift;
2055 my $state = \$pkg->{'state'};
2057 return if defined($$state) and $$state eq $newstate;
2058 $pkg->{'previous_state'} = $$state if defined($$state);
2059 $pkg->{'state_change'} = $curr_date;
2061 if (defined($$state) and $$state eq 'Failed') {
2062 $pkg->{'old_failed'} =
2063 "-"x20 . " $pkg->{'version'} " . "-"x20 . "\n" .
2064 $pkg->{'failed'} . "\n" .
2065 $pkg->{'old_failed'};
2066 delete $pkg->{'failed'};
2067 delete $pkg->{'failed_category'};
2069 if (defined($$state) and $$state eq 'BD-Uninstallable') {
2070 delete $pkg->{'bd_problem'};
2072 $$state = $newstate;
2078 my $dist = $distribution;
2082 $prevstate = $pkg->{'previous_state'};
2083 $str = "$action($dist): $pkg->{'package'}_$pkg->{'version'} ".
2084 "changed from $prevstate to $pkg->{'state'} ".
2085 "by $real_user as $user";
2087 $dbh->do('INSERT INTO ' . transactions_table_name() .
2088 ' (package, distribution, version, action, ' .
2089 ' prevstate, state, real_user, set_user, time) ' .
2090 ' values (?, ?, ?, ?, ?, ?, ?, ?, ?)',
2091 undef, $pkg->{'package'}, $distribution,
2092 $pkg->{'version'}, $action, $prevstate, $pkg->{'state'},
2093 $real_user, $user, 'now()') or die $dbh->errstr;
2095 if (!($prevstate eq 'Failed' && $pkg->{'state'} eq 'Failed')) {
2096 $str .= " (with --override)"
2098 $mail_logs .= "$str\n";
2105 my $subject = shift;
2108 my $from = $conf::db_maint;
2109 my $domain = $conf::buildd_domain;
2111 $from .= "\@$domain" if $from !~ /\@/;
2113 $to .= '@' . $domain if $to !~ /\@/;
2114 $text =~ s/^\.$/../mg;
2115 local $SIG{'PIPE'} = 'IGNORE';
2116 open( PIPE, "| $conf::mailprog -oem $to" )
2117 or die "Can't open pipe to $conf::mailprog: $!\n";
2119 print PIPE "From: $from\n";
2120 print PIPE "Subject: $subject\n\n";
2121 print PIPE "$text\n";
2125 # for parsing input to dep-wait
2131 foreach (split( /\s*,\s*/, $deps )) {
2133 # verification requires > starting prompts, no | crap
2134 if (!/^(\S+)\s*(\(\s*(>(?:[>=])?)\s*(\S+)\s*\))?\s*$/) {
2139 my @alts = split( /\s*\|\s*/, $_ );
2140 # Anything with an | is ignored, as it can be configured on a
2141 # per-buildd basis what will be installed
2142 next if $#alts != 0;
2145 if (!/^(\S+)\s*(\(\s*(>=|=|==|>|>>|<<|<=)\s*(\S+)\s*\))?\s*$/) {
2146 warn( "parse_deplist: bad dependency $_\n" );
2149 my($dep, $rel, $relv) = ($1, $3, $4);
2150 $rel = ">>" if defined($rel) and $rel eq ">";
2151 $result{$dep}->{'package'} = $dep;
2152 if ($rel && $relv) {
2153 $result{$dep}->{'rel'} = $rel;
2154 $result{$dep}->{'version'} = $relv;
2157 return 1 if $verify;
2165 foreach $key (keys %$list) {
2166 $result .= ", " if $result;
2168 $result .= " ($list->{$key}->{'rel'} $list->{$key}->{'version'})"
2169 if $list->{$key}->{'rel'} && $list->{$key}->{'version'};
2174 sub call_edos_depcheck {
2175 my $packagesfile = shift;
2179 return if defined ($conf::distributions{$distribution}{noadw});
2181 # We need to check all of needs-build, as any new upload could make
2182 # something in needs-build have uninstallable deps
2183 # We also check everything in bd-uninstallable, as any new upload could
2184 # make that work again
2185 my %interesting_packages;
2186 my $db = get_all_source_info();
2187 foreach $key (keys %$db) {
2188 my $pkg = $db->{$key};
2189 if (defined $pkg and isin($pkg->{'state'}, qw/Needs-Build BD-Uninstallable/)) {
2190 $interesting_packages{$key} = undef;
2194 #print "I would look at these sources with edos-depcheck:\n";
2195 #print join " ", keys %interesting_packages,"\n";
2197 my $tmpfile_pattern = "/tmp/wanna-build-interesting-sources-$distribution.$$-";
2199 for( $i = 0;; ++$i ) {
2200 $tmpfile = $tmpfile_pattern . $i;
2201 last if ! -e $tmpfile;
2204 open SOURCES, '>', $tmpfile or die "Could not open temporary file $tmpfile\n";
2205 for my $key (keys %interesting_packages) {
2206 my $pkg = $db->{$key};
2207 print SOURCES "Package: $key\n";
2208 print SOURCES "Version: $pkg->{'version'}\n";
2209 print SOURCES "Build-Depends: $srcs->{$key}{'dep'}\n" if $srcs->{$key}{'dep'};
2210 print SOURCES "Build-Conflicts: $srcs->{$key}{'conf'}\n" if $srcs->{$key}{'conf'};
2211 print SOURCES "Architecture: all\n";
2216 if (open(EDOS,"-|","wb-edos-builddebcheck", "-a", $arch, $packagesfile, $tmpfile))
2218 local($/) = ""; # read in paragraph mode
2220 my( $key, $reason ) ;
2222 /^Package:\s*(\S+)$/mi and $key = $1;
2223 /^Failed-Why:(([^\n]|\n ([^\n]|\.))*)$/msi and $reason = $1;
2224 $reason =~ s/^\s*//mg;
2225 $reason ||= 'No reason given by edos-debcheck';
2227 if (exists $interesting_packages{$key}) {
2228 $interesting_packages{$key} = $reason;
2230 #print "TODO: edos reported a package we do not care about now\n" if $verbose;
2235 print "ERROR: Could not run wb-edos-builddebcheck. I am continuing, assuming\n" .
2236 "all packages have installable build-dependencies."
2241 for my $key (keys %interesting_packages) {
2242 my $pkg = $db->{$key};
2244 (defined $interesting_packages{$key} and $pkg->{'state'} eq 'Needs-Build') ||
2245 (not defined $interesting_packages{$key} and $pkg->{'state'} eq 'BD-Uninstallable');
2246 my $problemchange = $interesting_packages{$key} ne $pkg->{'bd_problem'};
2248 if (defined $interesting_packages{$key}) {
2249 change_state( \$pkg, 'BD-Uninstallable' );
2250 $pkg->{'bd_problem'} = $interesting_packages{$key};
2252 change_state( \$pkg, 'Needs-Build' );
2255 if ($problemchange) {
2256 if (defined $interesting_packages{$key}) {
2257 $pkg->{'bd_problem'} = $interesting_packages{$key};
2261 log_ta( $pkg, "--merge-all" );
2262 print "edos-builddebchange changed state of ${key}_$pkg->{'version'} to $pkg->{'state'}\n" if $verbose;
2264 if ($change || $problemchange) {
2265 update_source_info($pkg);
2272 ($prgname = $0) =~ s,^.*/,,;
2274 Usage: $prgname <options...> <package_version...>
2276 -v, --verbose: Verbose execution.
2277 -A arch: Architecture this operation is for.
2278 --take: Take package for building [default operation]
2279 -f, --failed: Record in database that a build failed due to
2280 deficiencies in the package (that aren't fixable without a new
2282 -u, --uploaded: Record in the database that the packages build
2283 correctly and were uploaded.
2284 -n, --no-build: Record in the database that the packages aren't
2285 desired for this architecture and shouldn't appear in listings even
2286 if they're out of date.
2287 --dep-wait: Record in the database that the packages are waiting
2288 for some source dependencies to become available
2289 --binNMU num: Schedule a re-build of the package with unchanged source, but
2290 a new version number (source-version + "+b<num>")
2291 --give-back: Mark a package as ready to build that is in state Building,
2292 Built or Build-Attempted. To give back a package in state Failed, use
2293 --override. This command will actually put the package in state
2294 BD-Uninstallable, until the installability of its Build-Dependencies
2295 were verified. This happens at each call of --merge-all, usually
2297 --merge-quinn: Merge quinn-diff output into database.
2298 --merge-packages: Merge Packages files into database.
2299 --pretend-avail: Pretend that given packages are available now and give
2300 free packages waiting for them
2301 -i SRC_PKG, --info SRC_PKG: Show information for source package
2302 -l STATE, --list=STATE: List all packages in state STATE; can be
2303 combined with -U to restrict to a specific user; STATE can
2305 -m MESSAGE, --message=MESSAGE: Give reason why package failed or
2306 source dependency list
2307 (used with -f, --dep-wait, and --binNMU)
2308 -o, --override: Override another user's lock on a package, i.e.
2309 take it over; a notice mail will be sent to the other user
2310 -U USER, --user=USER: select user name for which listings should
2311 apply, if not given all users are listed.
2312 if -l is missing, set user name to be entered in db; usually
2313 automatically choosen
2314 --import FILE: Import database from a ASCII file FILE
2315 --export FILE: Export database to a ASCII file FILE
2317 The remaining arguments (depending on operation) usually start with
2318 "name_version", the trailer is ignored. This allows to pass the names
2319 of .dsc files, for which file name completion can be used.
2320 --merge-packages and --merge-quinn take Package/quin--diff file names
2321 on the command line or read stdin. --list needs nothing more on the
2322 command line. --info takes source package names (without version).
2327 sub pkg_version_eq {
2329 my $version = shift;
2332 if (defined $pkg->{'binary_nmu_version'}) and
2333 version_compare(binNMU_version($pkg->{'version'},
2334 $pkg->{'binary_nmu_version'}),'=', $version);
2335 return version_compare( $pkg->{'version'}, "=", $version );
2339 return '"' . $arch . $schema_suffix . '".packages';
2342 sub user_table_name {
2343 return '"' . $arch . $schema_suffix . '".users';
2346 sub transactions_table_name {
2347 return '"' . $arch . $schema_suffix . '".transactions';
2350 sub get_readonly_source_info {
2352 my $pkg = $dbh->selectrow_hashref('SELECT * FROM ' .
2353 table_name() . ' WHERE package = ? AND distribution = ?',
2354 undef, $name, $distribution);
2358 sub get_source_info {
2360 my $pkg = $dbh->selectrow_hashref('SELECT * FROM ' .
2361 table_name() . ' WHERE package = ? AND distribution = ?' .
2363 undef, $name, $distribution);
2367 sub get_all_source_info {
2370 my $q = 'SELECT * FROM ' . table_name()
2371 . ' WHERE distribution = ? ';
2372 my @args = ($distribution);
2373 if ($options{state} && uc($options{state}) ne "ALL") {
2374 $q .= ' AND upper(state) = ? ';
2375 push @args, uc($options{state});
2378 if ($options{user}) {
2379 #this basically means "this user, or no user at all":
2380 $q .= ' AND (builder = ? OR upper(state) = ?)';
2381 push @args, $options{user};
2382 push @args, "NEEDS-BUILD";
2385 if ($options{category}) {
2386 $q .= ' AND failed_category <> ? AND upper(state) = ? ';
2387 push @args, $options{category};
2388 push @args, "FAILED";
2391 if ($options{list_min_age} > 0) {
2392 $q .= ' AND age(state_change::timestamp) > ? ';
2393 push @args, $options{list_min_age} . " days";
2396 if ($options{list_min_age} < 0) {
2397 $q .= ' AND age(state_change::timestamp) < ? ';
2398 push @args, -$options{list_min_age} . " days";
2401 my $db = $dbh->selectall_hashref($q, 'package', undef, @args);
2405 sub update_source_info {
2408 my $pkg2 = get_source_info($pkg->{'package'});
2409 if (! defined $pkg2)
2411 add_source_info($pkg);
2414 $dbh->do('UPDATE ' . table_name() . ' SET ' .
2419 'installed_version = ?, ' .
2420 'previous_state = ?, ' .
2421 'state_change = ?, ' .
2425 'old_failed = ?, ' .
2426 'binary_nmu_version = ?, ' .
2427 'binary_nmu_changelog = ?, ' .
2428 'failed_category = ?, ' .
2429 'permbuildpri = ?, ' .
2434 'WHERE package = ? AND distribution = ?',
2440 $pkg->{'installed_version'},
2441 $pkg->{'previous_state'},
2442 $pkg->{'state_change'},
2446 $pkg->{'old_failed'},
2447 $pkg->{'binary_nmu_version'},
2448 $pkg->{'binary_nmu_changelog'},
2449 $pkg->{'failed_category'},
2450 $pkg->{'permbuildpri'},
2454 $pkg->{'bd_problem'},
2456 $distribution) or die $dbh->errstr;
2459 sub add_source_info {
2461 $dbh->do('INSERT INTO ' . table_name() .
2462 ' (package, distribution) values (?, ?)',
2463 undef, $pkg->{'package'}, $distribution) or die $dbh->errstr;
2466 sub del_source_info {
2468 $dbh->do('DELETE FROM ' . table_name() .
2469 ' WHERE package = ? AND distribution = ?',
2470 undef, $name, $distribution) or die $dbh->errstr;
2475 my $user = $dbh->selectrow_hashref('SELECT * FROM ' .
2476 user_table_name() . ' WHERE username = ? AND distribution = ?',
2477 undef, $name, $distribution);
2481 sub update_user_info {
2483 $dbh->do('UPDATE ' . user_table_name() .
2484 ' SET last_seen = now() WHERE username = ?' .
2485 ' AND distribution = ?',
2486 undef, $user, $distribution)
2487 or die $dbh->errstr;
2493 $dbh->do('INSERT INTO ' . user_table_name() .
2494 ' (username, distribution, last_seen)' .
2495 ' values (?, ?, now())',
2496 undef, $user, $distribution)
2497 or die $dbh->errstr;
2502 $dbh->do('LOCK TABLE ' . table_name() .
2503 ' IN EXCLUSIVE MODE', undef) or die $dbh->errstr;