1 package Packages::DoDownload;
9 use Benchmark ':hireswallclock';
13 use Packages::I18N::Locale;
14 use Packages::Search qw( :all );
15 use Packages::Config qw( $DBDIR @SUITES @ARCHIVES @SECTIONS @ARCHITECTURES );
19 our @ISA = qw( Exporter );
20 our @EXPORT = qw( do_download );
24 my ($params, $opts, $page_content) = @_;
26 if ($params->{errors}{package}) {
27 fatal_error( _g( "package not valid or not specified" ) );
29 if ($params->{errors}{suite}) {
30 fatal_error( _g( "suite not valid or not specified" ) );
32 if ($params->{errors}{arch}) {
33 fatal_error( _g( "architecture not valid or not specified" ) );
35 if (@{$opts->{suite}} > 1) {
36 fatal_error( sprintf( _g( "more than one suite specified for download (%s)" ), "@{$opts->{suite}}" ) );
38 if (@{$opts->{arch}} > 1) {
39 fatal_error( sprintf( _g( "more than one architecture specified for download (%s)" ), "@{$opts->{arch}}" ) );
42 $opts->{h_sections} = { map { $_ => 1 } @SECTIONS };
43 my $pkg = $opts->{package};
44 my $suite = $opts->{suite}[0];
45 my $arch = $opts->{arch}[0] ||'';
49 my ($final_result, $filename, $directory, @file_components, $archive) = ("")x5;
51 my $st0 = new Benchmark;
52 unless (@Packages::CGI::fatal_errors) {
53 tie %packages_all, 'DB_File', "$DBDIR/packages_all_$suite.db",
54 O_RDONLY, 0666, $DB_BTREE
55 or die "couldn't tie DB $DBDIR/packages_all_$suite.db: $!";
57 read_entry( \%packages, $pkg, \@results, $opts );
59 @results = grep { $_->[7] ne 'v' } @results;
61 # fatal_error( _g( "No such package." )."<br>".
62 # sprintf( _g( '<a href="%s">Search for the package</a>' ), "$SEARCH_URL/$pkg" ) );
64 my $final_result = shift @results;
66 if (version_cmp( $_->[7], $final_result->[7] ) > 0) {
71 debug( "final_result=@$final_result", 1 );
72 $archive = $final_result->[1];
73 my %data = split /\000/, $packages_all{"$pkg $arch $final_result->[7]"};
74 if (!%data && $arch ne 'all' && $final_result->[3] eq 'all') {
75 %data = split /\000/, $packages_all{"$pkg all $final_result->[7]"};
77 debug( "choosing arch 'all' instead of requested arch $arch", 1 );
78 # fatal_error( _g( "No such package." )."<br>".
79 # sprintf( _g( '<a href="%s">Search for the package</a>' ), "$SEARCH_URL/$pkg" ) ) unless %data;
81 @file_components = split('/', $data{filename});
82 $filename = pop(@file_components);
83 $directory = join( '/', @file_components).'/';
85 $page_content->{archive} = $archive;
86 $page_content->{suite} = $suite;
87 $page_content->{pkg} = $pkg;
88 $page_content->{pkgsize} = sprintf( '%.1f', floor(($data{size}/102.4)+0.5)/10 );
89 $page_content->{pkgsize_unit} = _g( 'kByte' );
90 if ($page_content->{pkgsize} > 1024) {
91 $page_content->{pkgsize} = sprintf( '%.1f', floor(($data{size}/(102.4*102.4))+0.5)/100 );
92 $page_content->{pkgsize_unit} = _g( 'MByte' );
94 $page_content->{architecture} = $arch;
95 foreach (keys %data) {
96 $page_content->{$_} = $data{$_};
98 $page_content->{filename} = { file => $filename,
99 directory => $directory,
100 full => $data{filename},