]> git.donarmstrong.com Git - wannabuild.git/blobdiff - bin/wanna-build
Make list use state field in the sql select.
[wannabuild.git] / bin / wanna-build
index 4a528a3d9ac15c80bdb15027dda424c505bdd3f9..a079c295da46adf4df777a8c46d63a88382c101d 100755 (executable)
@@ -303,8 +303,7 @@ END {
 }
 
 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/) {
        $dbh = DBI->connect("DBI:Pg:service=wanna-build") || 
                die "FATAL: Cannot open database: $DBI::errstr\n";
        $schema_suffix = '_public';
@@ -1760,12 +1759,16 @@ sub list_packages {
        my $cnt = 0;
        my %scnt;
        my $ctime = time;
+       my $db;
 
-       my $db = get_all_source_info();
+       if ($state ne "all") {
+               $db = get_all_source_info_state($state);
+       } else {
+               $db = get_all_source_info();
+       }
        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;
@@ -1832,7 +1835,7 @@ sub info_packages {
                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;
@@ -2350,6 +2353,7 @@ sub usage {
 Usage: $prgname <options...> <package_version...>
 Options:
     -v, --verbose: Verbose execution.
+    -A arch: Architecture this operation is for.
     --take: Take package for building [default operation]
     -f, --failed: Record in database that a build failed due to
         deficiencies in the package (that aren't fixable without a new
@@ -2417,7 +2421,7 @@ sub user_table_name {
        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 = ?',
@@ -2425,6 +2429,15 @@ sub get_source_info {
        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 = ?',
@@ -2432,6 +2445,14 @@ sub get_all_source_info {
        return $db;
 }
 
+sub get_all_source_info_state {
+       my $state = shift;
+       my $db = $dbh->selectall_hashref('SELECT * FROM ' . table_name() .
+               ' WHERE distribution = ? and state = ?',
+               'package', undef, $distribution, $state);
+       return $db;
+}
+
 sub update_source_info {
        my $pkg = shift;