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) = @_;
25 my $cat = $opts->{cat};
27 if ($params->{errors}{package}) {
28 fatal_error( $cat->g( "package not valid or not specified" ) );
30 if ($params->{errors}{suite}) {
31 fatal_error( $cat->g( "suite not valid or not specified" ) );
33 if ($params->{errors}{arch}) {
34 fatal_error( $cat->g( "architecture not valid or not specified" ) );
36 if (@{$opts->{suite}} > 1) {
37 fatal_error( $cat->g( "more than one suite specified for download (%s)",
38 "@{$opts->{suite}}" ) );
40 if (@{$opts->{arch}} > 1) {
41 fatal_error( $cat->g( "more than one architecture specified for download (%s)",
42 "@{$opts->{arch}}" ) );
45 $opts->{h_sections} = { map { $_ => 1 } @SECTIONS };
46 my $pkg = $opts->{package};
47 my $suite = $opts->{suite}[0];
48 my $arch = $opts->{arch}[0] ||'';
52 my ($final_result, $filename, $directory, @file_components, $archive) = ("")x5;
54 my $st0 = new Benchmark;
55 unless (@Packages::CGI::fatal_errors) {
56 tie %packages_all, 'DB_File', "$DBDIR/packages_all_$suite.db",
57 O_RDONLY, 0666, $DB_BTREE
58 or die "couldn't tie DB $DBDIR/packages_all_$suite.db: $!";
60 read_entry( \%packages, $pkg, \@results, $opts );
62 @results = grep { $_->[7] ne 'v' } @results;
64 # fatal_error( _g( "No such package." )."<br>".
65 # sprintf( _g( '<a href="%s">Search for the package</a>' ), "$SEARCH_URL/$pkg" ) );
67 my $final_result = shift @results;
69 if (version_cmp( $_->[7], $final_result->[7] ) > 0) {
74 debug( "final_result=@$final_result", 1 );
75 $archive = $final_result->[1];
76 my %data = split /\000/, $packages_all{"$pkg $arch $final_result->[7]"};
77 if (!%data && $arch ne 'all' && $final_result->[3] eq 'all') {
78 %data = split /\000/, $packages_all{"$pkg all $final_result->[7]"};
80 debug( "choosing arch 'all' instead of requested arch $arch", 1 );
81 # fatal_error( _g( "No such package." )."<br>".
82 # sprintf( _g( '<a href="%s">Search for the package</a>' ), "$SEARCH_URL/$pkg" ) ) unless %data;
84 @file_components = split('/', $data{filename});
85 $filename = pop(@file_components);
86 $directory = join( '/', @file_components).'/';
88 $page_content->{archive} = $archive;
89 $page_content->{suite} = $suite;
90 $page_content->{pkg} = $pkg;
91 my $pkgsize = floor(($data{size}/102.4)+0.5)/10;
92 if ($pkgsize < 1024) {
93 $page_content->{pkgsize} = sprintf( '%.1f', $pkgsize );
94 $page_content->{pkgsize_unit} = $cat->g( 'kByte' );
96 $page_content->{pkgsize} = sprintf( '%.1f', floor(($data{size}/(102.4*102.4))+0.5)/100 );
97 $page_content->{pkgsize_unit} = $cat->g( 'MByte' );
99 $page_content->{architecture} = $arch;
100 foreach (keys %data) {
101 $page_content->{$_} = $data{$_};
103 $page_content->{filename} = { file => $filename,
104 directory => $directory,
105 full => $data{filename},