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,
68 'debug|d+','help|h|?','man|m');
70 pod2usage() if $options{help};
71 pod2usage({verbose=>2}) if $options{man};
73 $DEBUG = $options{debug};
79 "You must provide at least four arguments, two databases, ".
80 "a top level directory and at least one suite";
83 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
86 my $versions = shift @ARGV;
87 my $versions_time = shift @ARGV;
88 my $toplevel = shift @ARGV;
91 $MLDBM::DumpMeth=q(portable);
97 tie %db, "MLDBM", $versions, O_CREAT|O_RDWR, 0664
98 or die "tie $versions: $!";
99 tie %db2, "MLDBM", $versions_time,O_CREAT|O_RDWR, 0664
100 or die "tie $versions_time failed: $!";
102 # Read Package, Version, and Source fields from a Packages.gz file.
104 my ($packages, $component,$arch,$dist) = @_;
105 my $PACKAGES = IO::Uncompress::AnyUncompress->new($packages) or
106 die "Unable to open $packages for reading: $!";
108 local $/ = ''; # paragraph mode
110 print STDERR "reading packages $packages\n" if $DEBUG;
112 /^Package: (.+)/im or next;
114 /^Version: (.+)/im or next;
116 my $extra_source_only = 0;
117 if (/^Extra-Source-Only: yes/im) {
118 $extra_source_only = 1;
120 update_package_version($dist,$arch,$pkg,$ver,$time) unless
126 sub update_package_version {
127 my ($d,$a,$p,$v,$t) = @_;
128 # see MLDBM(3pm)/BUGS
130 # we allow multiple versions in an architecture now; this
131 # should really only happen in the case of source, however.
132 push @{$tmp->{$d}{$a}}, $v;
135 $tmp->{$d}{$a}{$v} = $time if not exists
140 # Iterate through all Packages and Sources files.
141 for my $suite (@suites) {
142 my $suitedir = "$toplevel/$suite";
144 for my $component ('main', 'main/debian-installer',
145 'contrib', 'non-free') {
146 my $componentdir = "$suitedir/$component";
147 next unless -d $componentdir;
149 opendir $COMPONENT, $componentdir or die "opendir $componentdir: $!";
151 # debian-installer is really a section rather than a component
153 (my $viscomponent = $component) =~ s[/.*][];
155 my $sources = (grep { -f $_ } glob "$suitedir/$component/source/Sources.*")[0];
156 next unless defined $sources;
157 read_packages($sources, $viscomponent,'source',$suite);
159 for my $arch (readdir $COMPONENT) {
160 next unless $arch =~ s/^binary-//;
161 my $archdir = "$componentdir/binary-$arch";
163 my $packages = (grep { -f $_ } glob("$archdir/Packages.*"))[0];
164 next unless defined $packages;
165 read_packages($packages, $viscomponent,$arch,$suite);