X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FNNTPD.pm;h=117c9c0379febe77b680e69cd693858760212325;hb=3d41aa23f35501ca92aab8aa42980fa73f7fa74f;hp=85109ea7ed57b722d8822c51339635c4b8ca6649;hpb=85c83085eeb14be7e7b9a395fa9408241ecb8244;p=public-inbox.git diff --git a/lib/PublicInbox/NNTPD.pm b/lib/PublicInbox/NNTPD.pm index 85109ea7..117c9c03 100644 --- a/lib/PublicInbox/NNTPD.pm +++ b/lib/PublicInbox/NNTPD.pm @@ -1,4 +1,4 @@ -# Copyright (C) 2016 all contributors +# Copyright (C) 2016-2018 all contributors # License: AGPL-3.0+ # represents an NNTPD (currently a singleton), @@ -6,7 +6,6 @@ package PublicInbox::NNTPD; use strict; use warnings; -require PublicInbox::NewsGroup; require PublicInbox::Config; sub new { @@ -24,33 +23,19 @@ sub refresh_groups () { my $pi_config = PublicInbox::Config->new; my $new = {}; my @list; - foreach my $k (keys %$pi_config) { - $k =~ /\Apublicinbox\.([^\.]+)\.mainrepo\z/ or next; - my $g = $1; - my $git_dir = $pi_config->{$k}; - my $addr = $pi_config->{"publicinbox.$g.address"}; - my $ngname = $pi_config->{"publicinbox.$g.newsgroup"}; - if (defined $ngname) { - next if ($ngname eq ''); # disabled - $g = $ngname; - } - my $ng = PublicInbox::NewsGroup->new($g, $git_dir, $addr); - my $old_ng = $self->{groups}->{$g}; - - # Reuse the old one if possible since it can hold - # references to valid mm and gcf objects - if ($old_ng) { - $old_ng->update($ng); - $ng = $old_ng; - } - - # Only valid if msgmap and search works - if ($ng->usable) { - $new->{$g} = $ng; + $pi_config->each_inbox(sub { + my ($ng) = @_; + my $ngname = $ng->{newsgroup} or return; + if (ref $ngname) { + warn 'multiple newsgroups not supported: '. + join(', ', @$ngname). "\n"; + } elsif ($ng->nntp_usable) { + # Only valid if msgmap and search works + $new->{$ngname} = $ng; push @list, $ng; } - } - @list = sort { $a->{name} cmp $b->{name} } @list; + }); + @list = sort { $a->{newsgroup} cmp $b->{newsgroup} } @list; $self->{grouplist} = \@list; # this will destroy old groups that got deleted %{$self->{groups}} = %$new;