use Storable qw(dclone);
use Params::Validate qw(validate_with :types);
use Debbugs::Common qw(make_list globify_scalar sort_versions);
-
+use DateTime::Format::Pg;
use List::AllUtils qw(min max uniq);
use IO::File;
my @archs = grep {defined $_} make_list(exists $param{arch}?$param{arch}:[]);
return () unless @binaries;
+ my $cache_key = join("\1",
+ join("\0",@binaries),
+ join("\0",@versions),
+ join("\0",@archs),
+ join("\0",@param{qw(source_only scalar_only)}));
+ if (exists $param{cache}{$cache_key}) {
+ return $param{scalar_only} ? $param{cache}{$cache_key}[0]:
+ @{$param{cache}{$cache_key}};
+ }
# any src:foo is source package foo with unspecified version
@source = map {/^src:(.+)$/?
[$1,'']:()} @binaries;
push @source,
map {$_->{pkg}} $src_rs->all;
if ($param{scalar_only}) {
- return join(',',@source);
+ @source = join(',',@source);
}
- return @source;
-
+ $param{cache}{$cache_key} = \@source;
+ return $param{scalar_only}?$source[0]:@source;
}
my $src_rs = $param{schema}->resultset('SrcVer')->
search_rs({'bin_pkg.pkg' => [@binaries],
$_->{src_vers}{ver},
]} $src_rs->all;
}
- return @source;
- }
- my $cache_key = join("\1",
- join("\0",@binaries),
- join("\0",@versions),
- join("\0",@archs),
- join("\0",@param{qw(source_only scalar_only)}));
- if (exists $param{cache}{$cache_key}) {
- return $param{scalar_only} ? $param{cache}{$cache_key}[0]:
- @{$param{cache}{$cache_key}};
+ $param{cache}{$cache_key} = \@source;
+ return $param{scalar_only}?$source[0]:@source;
}
for my $binary (@binaries) {
_tie_binarytosource;
=item version -- binary package version(s) as a SCALAR or ARRAYREF;
optional, defaults to all versions.
-=item arch -- binary package architecture(s) as a SCALAR or ARRAYREF;
-optional, defaults to all architectures.
+=item dist -- list of distributions to return corresponding binary packages for
+as a SCALAR or ARRAYREF.
=item binary_only -- return only the source name (forced on if in SCALAR
context), defaults to false. [If in LIST context, returns a list of binary
version => {type => SCALAR|ARRAYREF,
optional => 1,
},
+ dist => {type => SCALAR|ARRAYREF,
+ optional => 1,
+ },
binary_only => {default => 0,
},
scalar_only => {default => 0,
distinct => 1,
},
);
+ if (exists $param{dist}) {
+ $bin_rs = $bin_rs->
+ search({-or =>
+ {'suite.codename' => [make_list($param{dist})],
+ 'suite.suite_name' => [make_list($param{dist})],
+ }},
+ {join => {'bin_vers' =>
+ {'bin_associations' =>
+ 'suite'
+ }},
+ });
+ }
push @binaries,
map {$_->{pkg}} $bin_rs->all;
if ($param{scalar_only}) {
largest_source_version_only => {type => BOOLEAN,
default => 1,
},
+ schema => {type => OBJECT,
+ optional => 1,
+ },
},
- );
+ );
+ if (defined $param{schema}) {
+ my @src_packages;
+ my @bin_packages;
+ for my $pkg (make_list($param{package})) {
+ if ($pkg =~ /^src:(.+)/) {
+ push @src_packages,
+ $1;
+ } else {
+ push @bin_packages,$pkg;
+ }
+ }
+
+ my $s = $param{schema};
+ my %return;
+ if (@src_packages) {
+ my $src_rs = $s->resultset('SrcVer')->
+ search({'src_pkg.pkg'=>[@src_packages],
+ -or => {'suite.codename' => [make_list($param{dist})],
+ 'suite.suite_name' => [make_list($param{dist})],
+ }
+ },
+ {join => ['src_pkg',
+ {
+ src_associations=>'suite'},
+ ],
+ '+select' => [qw(src_pkg.pkg),
+ qw(suite.codename),
+ qw(src_associations.modified),
+ q(CONCAT(src_pkg.pkg,'/',me.ver))],
+ '+as' => ['src_pkg_name','codename',
+ 'modified_time',
+ qw(src_pkg_ver)],
+ result_class => 'DBIx::Class::ResultClass::HashRefInflator',
+ order_by => {-desc => 'me.ver'},
+ },
+ );
+ my %completed_dists;
+ for my $src ($src_rs->all()) {
+ my $val = 'source';
+ if ($param{time}) {
+ $val = DateTime::Format::Pg->
+ parse_datetime($src->{modified_time})->
+ epoch();
+ }
+ if ($param{largest_source_version_only}) {
+ next if $completed_dists{$src->{codename}};
+ $completed_dists{$src->{codename}} = 1;
+ }
+ if ($param{source}) {
+ $return{$src->{src_pkg_ver}} = $val;
+ } else {
+ $return{$src->{ver}} = $val;
+ }
+ }
+ }
+ if (@bin_packages) {
+ my $bin_rs = $s->resultset('BinVer')->
+ search({'bin_pkg.pkg' => [@bin_packages],
+ -or => {'suite.codename' => [make_list($param{dist})],
+ 'suite.suite_name' => [make_list($param{dist})],
+ },
+ },
+ {join => ['bin_pkg',
+ {
+ 'src_ver'=>'src_pkg'},
+ {
+ bin_associations => 'suite'},
+ 'arch',
+ ],
+ '+select' => [qw(bin_pkg.pkg arch.arch suite.codename),
+ qw(bin_associations.modified),
+ qw(src_pkg.pkg),q(CONCAT(src_pkg.pkg,'/',me.ver)),
+ ],
+ '+as' => ['bin_pkg','arch','codename',
+ 'modified_time',
+ 'src_pkg_name','src_pkg_ver'],
+ result_class => 'DBIx::Class::ResultClass::HashRefInflator',
+ order_by => {-desc => 'src_ver.ver'},
+ });
+ if (exists $param{arch}) {
+ $bin_rs =
+ $bin_rs->search({'arch.arch' => [make_list($param{arch})]},
+ {
+ join => 'arch'}
+ );
+ }
+ my %completed_dists;
+ for my $bin ($bin_rs->all()) {
+ my $key = $bin->{ver};
+ if ($param{source}) {
+ $key = $bin->{src_pkg_ver};
+ }
+ my $val = $bin->{arch};
+ if ($param{time}) {
+ $val = DateTime::Format::Pg->
+ parse_datetime($bin->{modified_time})->
+ epoch();
+ }
+ if ($param{largest_source_version_only}) {
+ if ($completed_dists{$bin->{codename}} and not
+ exists $return{$key}) {
+ next;
+ }
+ $completed_dists{$bin->{codename}} = 1;
+ }
+ push @{$return{$key}},
+ $val;
+ }
+ }
+ if ($param{return_archs}) {
+ if ($param{time} or $param{return_archs}) {
+ return wantarray?%return :\%return;
+ }
+ return wantarray?keys %return :[keys %return];
+ }
+ }
my $versions;
if ($param{time}) {
return () if not defined $gVersionTimeIndex;
warnings => {type => SCALARREF|HANDLE,
optional => 1,
},
+ schema => {type => OBJECT,
+ optional => 1,
+ },
},
);
my ($warnings) = globify_scalar(exists $param{warnings}?$param{warnings}:undef);