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