2 # build-versions-db builds the versions mldmb database
3 # and is released under the terms of the GNU GPL version 3, or any
4 # later version, at your option. See the file README and COPYING for
6 # Copyright 2016 by Don Armstrong <don@donarmstrong.com>.
17 build-versions-db -- builds source and source maintainers file
21 build-versions-db [options] versions.idx.new versions.idx.new \
22 /srv/bugs.debian.org/versions/indices/ftp
25 --debug, -d debugging level (Default 0)
26 --help, -h display this help
27 --man, -m display manual
35 Debug verbosity. (Default 0)
39 Display brief usage information.
49 build-versions-db versions.idx.new versions.idx.new \
50 /srv/bugs.debian.org/versions/indices/ftp \
57 use Debbugs::Versions::Dpkg;
58 use IO::Uncompress::AnyUncompress;
59 use MLDBM qw(DB_File Storable);
62 my %options = (debug => 0,
71 'debug|d+','help|h|?','man|m');
73 pod2usage() if $options{help};
74 pod2usage({verbose=>2}) if $options{man};
76 $DEBUG = $options{debug};
79 if (not defined $options{hostname}) {
80 push @USAGE_ERRORS,"You must provide a hostname";
85 "You must provide at least four arguments, two databases, ".
86 "a top level directory and at least one suite";
89 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
92 my $versions = shift @ARGV;
93 my $versions_time = shift @ARGV;
94 my $toplevel = shift @ARGV;
97 $MLDBM::DumpMeth=q(portable);
103 tie %db, "MLDBM", $versions, O_CREAT|O_RDWR, 0664
104 or die "tie $versions: $!";
105 tie %db2, "MLDBM", $versions_time,O_CREAT|O_RDWR, 0664
106 or die "tie $versions_time failed: $!";
108 # Read Package, Version, and Source fields from a Packages.gz file.
110 my ($packages, $component,$arch,$dist) = @_;
111 my $PACKAGES = IO::Uncompress::AnyUncompress->new($packages) or
112 die "Unable to open $packages for reading: $!";
114 local $/ = ''; # paragraph mode
116 print STDERR "reading packages $packages\n" if $DEBUG;
118 /^Package: (.+)/im or next;
120 /^Version: (.+)/im or next;
122 my $extra_source_only = 0;
123 if (/^Extra-Source-Only: yes/im) {
124 $extra_source_only = 1;
126 update_package_version($dist,$arch,$pkg,$ver,$time) unless
132 sub update_package_version {
133 my ($d,$a,$p,$v,$t) = @_;
134 # see MLDBM(3pm)/BUGS
136 # we allow multiple versions in an architecture now; this
137 # should really only happen in the case of source, however.
138 push @{$tmp->{$d}{$a}}, $v;
141 $tmp->{$d}{$a}{$v} = $time if not exists
146 # Iterate through all Packages and Sources files.
147 for my $suite (@suites) {
148 my $suitedir = "$toplevel/$suite";
150 for my $component ('main', 'main/debian-installer',
151 'contrib', 'non-free') {
152 my $componentdir = "$suitedir/$component";
153 next unless -d $componentdir;
155 opendir $COMPONENT, $componentdir or die "opendir $componentdir: $!";
157 # debian-installer is really a section rather than a component
159 (my $viscomponent = $component) =~ s[/.*][];
160 $viscomponent = $options{compprefix} . $viscomponent;
162 my $sources = (grep { -f $_ } glob "$suitedir/$component/source/Sources.*")[0];
163 next unless defined $sources;
164 read_packages($sources, $viscomponent,'source',$suite);
166 for my $arch (readdir $COMPONENT) {
167 next unless $arch =~ s/^binary-//;
168 my $archdir = "$componentdir/binary-$arch";
170 my $packages = (grep { -f $_ } glob("$archdir/Packages.*"))[0];
171 next unless defined $packages;
172 read_packages($packages, $viscomponent,$arch,$suite);