2 # maintainer-indices generates Maintainer.idx and Source.idx files
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 2018 by Don Armstrong <don@donarmstrong.com>.
17 maintainer-indices - generates Maintainer.idx and Source.idx files
21 maintainer-indices [options]
24 --debug, -d debugging level (Default 0)
25 --help, -h display this help
26 --man, -m display manual
34 Debug verbosity. (Default 0)
38 Display brief usage information.
55 use MLDBM qw(DB_File Storable);
56 $MLDBM::DumpMeth='portable';
59 use Debbugs::Config qw(:config);
60 use Debbugs::Common qw(lockpid getparsedaddrs);
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};
77 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
81 {source => {index => $config{spool_dir}.'/'.'source_maintainers.idx',
82 index_reverse => $config{spool_dir}.'/'.'source_maintainers_reverse.idx',
84 [@config{('source_maintainer_file',
85 'source_maintainer_file_override',
86 'pseudo_maint_file')}],
88 binary => {index => $config{spool_dir}.'/'.'binary_maintainers.idx',
89 index_reverse => $config{spool_dir}.'/'.'binary_maintainers_reverse.idx',
91 [@config{('maintainer_file',
92 'maintainer_file_override',
93 'pseudo_maint_file')}],
97 if (not lockpid($config{spool_dir}.'/lock/maintainer-indices')) {
98 print STDERR "Another maintainer-indices is running; stopping\n";
102 # tie new maint/source maint indexes for forward and reverse
103 for my $idx (keys %{$indexes}) {
104 for my $fr ('','_reverse') {
105 tie %{$indexes->{$idx}{"tie$fr"}},
106 MLDBM => $indexes->{$idx}{"index$fr"}.'-new',
107 O_CREAT|O_TRUNC|O_RDWR, 0644 or
108 die qq(Unable to tie $indexes->{$idx}{"index$fr"}-new: $!);
111 for my $idx (keys %{$indexes}) {
112 for my $fn (@{$indexes->{$idx}{files}}) {
113 next unless defined $fn and length $fn;
115 warn "Missing $idx maintainer file '$fn'";
118 add_to_index($fn,$indexes->{$idx}{tie},
119 $indexes->{$idx}{tie_reverse}
124 for my $idx (keys %{$indexes}) {
125 for my $fr ('','_reverse') {
126 move($indexes->{$idx}{"index$fr"}.'-new',
127 $indexes->{$idx}{"index$fr"}
134 my ($fn,$forward,$reverse,$type) = @_;
138 die "Unable to open $fn for reading: $!";
139 binmode($fh,':encoding(UTF-8)') or
140 die "Unable to set UTF-8 encoding: $!";
143 next unless m/^(\S+)\s+(\S.*\S)\s*$/;
144 my ($key,$value) = ($1,$2);
146 $forward->{$key} = $value;
148 if ($type eq 'address') {
149 @values = map {lc($_->address)}
150 getparsedaddrs($value);
152 for my $m (@values) {
153 # this is to work around a bug in tied hashes.
154 my $r = $reverse->{$m} // [];
160 die "Unable to close $fn filehandle: $!";
167 # indent-tabs-mode: nil
168 # cperl-indent-level: 4