code => sub {
die "Argument of --min-age must be a non-zero number\n"
if $list_min_age == 0;
- $list_min_age *= 24*60*60;
} },
"max-age" => { arg => \$list_min_age,
code => sub {
die "Argument of --max-age must be a non-zero number\n"
if $list_min_age == 0;
- $list_min_age *= -24*60*60;
+ $list_min_age *= -1;
} },
# special actions
import => { arg => \$import_from, mode => "import" },
}
my $schema_suffix = '';
-# TODO: Base this on something else, like an option that is passed.
-if ($real_user eq 'nobody') {
+if (isin( $op_mode, qw(list info)) && $distribution !~ /security/ && !(not -t and $user =~ /-/)) {
$dbh = DBI->connect("DBI:Pg:service=wanna-build") ||
die "FATAL: Cannot open database: $DBI::errstr\n";
$schema_suffix = '_public';
my %scnt;
my $ctime = time;
- my $db = get_all_source_info();
+ my $db = get_all_source_info(state => $state, user => $user, category => $category, list_min_age => $list_min_age);
foreach $name (keys %$db) {
next if $name =~ /^_/;
- $pkg = $db->{$name};
- next if $state ne "all" && $pkg->{'state'} !~ /^\Q$state\E$/i;
- next if $user && (lc($state) ne 'needs-build' and $pkg->{'builder'} ne $user);
- next if $category && $pkg->{'state'} eq "Failed" &&
- $pkg->{'failed_category'} ne $category;
- next if ($list_min_age > 0 &&
- ($ctime-parse_date($pkg->{'state_change'})) < $list_min_age)||
- ($list_min_age < 0 &&
- ($ctime-parse_date($pkg->{'state_change'})) > -$list_min_age);
- push( @list, $pkg );
+ push @list, $db->{$name};
}
foreach $pkg (sort sort_list_func @list) {
foreach $dist (@dists) {
my $pname = "$name" . ($info_all_dists ? "($dist)" : "");
- $pkg = get_source_info($name);
+ $pkg = get_readonly_source_info($name);
if (!defined( $pkg )) {
print "$pname: not registered\n";
next;
return '"' . $arch . $schema_suffix . '".users';
}
-sub get_source_info {
+sub get_readonly_source_info {
my $name = shift;
my $pkg = $dbh->selectrow_hashref('SELECT * FROM ' .
table_name() . ' WHERE package = ? AND distribution = ?',
return $pkg;
}
+sub get_source_info {
+ my $name = shift;
+ my $pkg = $dbh->selectrow_hashref('SELECT * FROM ' .
+ table_name() . ' WHERE package = ? AND distribution = ?' .
+ 'FOR UPDATE',
+ undef, $name, $distribution);
+ return $pkg;
+}
+
sub get_all_source_info {
- my $db = $dbh->selectall_hashref('SELECT * FROM ' . table_name() .
- ' WHERE distribution = ?',
- 'package', undef, $distribution);
+ my %options = @_;
+
+ my $q = 'SELECT * FROM ' . table_name()
+ . ' WHERE distribution = ? ';
+ my @args = ($distribution);
+ if (uc($options{state}) ne "ALL") {
+ $q .= ' AND upper(state) = ? ';
+ push @args, uc($options{state});
+ }
+
+ if ($options{user}) {
+ #this basically means "this user, or no user at all":
+ $q .= ' AND (builder = ? OR upper(state) = ?)';
+ push @args, $options{user};
+ push @args, "NEEDS-BUILD";
+ }
+
+ if ($options{category}) {
+ $q .= ' AND failed_category <> ? AND upper(state) = ? ';
+ push @args, $options{category};
+ push @args, "FAILED";
+ }
+
+ if ($options{list_min_age} > 0) {
+ $q .= ' AND age(state_change::timestamp) > ? ';
+ push @args, $options{list_min_age} . " days";
+ }
+
+ if ($options{list_min_age} < 0) {
+ $q .= ' AND age(state_change::timestamp) < ? days ';
+ push @args, -$options{list_min_age} . " days";
+ }
+
+ my $db = $dbh->selectall_hashref($q, 'package', undef, @args);
return $db;
}