]> git.deb.at Git - deb/packages.git/blob - lib/Packages/DoIndex.pm
Packages::DoIndex: No translated allpackages.*.txt.gz available
[deb/packages.git] / lib / Packages / DoIndex.pm
1 package Packages::DoIndex;
2
3 use strict;
4 use warnings;
5
6 use CGI qw( :cgi );
7 use Exporter;
8
9 use Deb::Versions;
10 use Packages::Config qw( $TOPDIR );
11 use Packages::CGI;
12
13 our @ISA = qw( Exporter );
14 our @EXPORT = qw( do_index do_allpackages );
15
16 sub do_index {
17     return send_file( 'index', @_ );
18 }
19 sub do_allpackages {
20     return send_file( 'allpackages', @_ );
21 }
22
23 my %encoding = (
24                 'txt.gz' => 'x-gzip',
25                 );
26 sub send_file {
27     my ($file, $params, $opts) = @_;
28     my $cat = $opts->{cat};
29
30     if ($params->{errors}{suite}) {
31         fatal_error( $cat->g( "suite not valid or not specified" ) );
32     }
33     if (@{$opts->{suite}} > 1) {
34         fatal_error( $cat->g( "more than one suite specified for show_static (%s)",
35                               "@{$opts->{suite}}" ) );
36     }
37     if (@{$opts->{subsection}} > 1) {
38         fatal_error( $cat->g( "more than one subsection specified for show_static (%s)",
39                               "@{$opts->{suite}}" ) );
40     }
41
42     if ($opts->{format} eq 'txt.gz') {
43         $opts->{po_lang} = 'en';
44     }
45     my $wwwdir = "$TOPDIR/www";
46     my $path = "";
47     $path .= "source/" if $opts->{source};
48     $path .= "$opts->{suite}[0]/";
49     $path .= "$opts->{archive}[0]/" if @{$opts->{archive}} == 1;
50     $path .= "$opts->{subsection}[0]/" if @{$opts->{subsection}};
51     $path .= "$opts->{priority}[0]/" if @{$opts->{priority}};
52     $path .= "$file.$opts->{po_lang}.$opts->{format}";
53
54     unless (@Packages::CGI::fatal_errors) {
55         my $buffer;
56         if (open( INDEX, '<', "$wwwdir/$path" )) {
57             my %headers;
58             $headers{'-charset'} = 'UTF-8';
59             $headers{'-type'} = get_mime( $opts->{format}, 'text/plain' );
60             $headers{'-content-encoding'} = $encoding{$opts->{format}} if exists $encoding{$opts->{format}};
61             my ($size,$mtime) = (stat("$wwwdir/$path"))[7,9];
62             $headers{'-content-length'} = $size;
63             $headers{'-last-modified'} = gmtime($mtime);
64             print header( %headers );
65
66             binmode INDEX;
67             while (read INDEX, $buffer, 4096) {
68                 print $buffer;
69             }
70             close INDEX;
71             exit;
72         } else {
73             fatal_error( $cat->g( "couldn't read index file %s: %s",
74                                   $path, $! ) );
75         }
76     }
77 }
78
79 1;
80