1 # Copyright (C) 2015 all contributors <meta@public-inbox.org>
2 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
4 # Used only by the NNTP server to represent a public-inbox git repository
6 package PublicInbox::NewsGroup;
9 use Scalar::Util qw(weaken);
10 require Danga::Socket;
11 require PublicInbox::Msgmap;
12 require PublicInbox::Search;
13 require PublicInbox::Git;
16 my ($class, $name, $git_dir, $address) = @_;
17 $address = $address->[0] if ref($address);
23 $self->{domain} = ($address =~ /\@(\S+)\z/) ? $1 : 'localhost';
28 my ($self, $field) = @_;
29 Danga::Socket->AddTimer(30, sub { weaken($self->{$field}) });
34 $self->{gcf} ||= eval {
35 my $gcf = PublicInbox::Git->new($self->{git_dir});
37 # git repos may be repacked and old packs unlinked
38 defer_weaken($self, 'gcf');
46 PublicInbox::Msgmap->new($self->{git_dir});
47 PublicInbox::Search->new($self->{git_dir});
53 $self->{mm} ||= eval {
54 my $mm = PublicInbox::Msgmap->new($self->{git_dir});
56 # may be needed if we run low on handles
57 defer_weaken($self, 'mm');
64 $self->{search} ||= eval {
65 my $search = PublicInbox::Search->new($self->{git_dir});
67 # may be needed if we run low on handles
68 defer_weaken($self, 'search');
75 open my $fh, '<', "$self->{git_dir}/description" or return '';
76 my $desc = eval { local $/; <$fh> };
83 my ($self, $new) = @_;
84 $self->{address} = $new->{address};
85 $self->{domain} = $new->{domain};
86 if ($self->{git_dir} ne $new->{git_dir}) {
87 # new git_dir requires a new mm and gcf
88 $self->{mm} = $self->{gcf} = undef;
89 $self->{git_dir} = $new->{git_dir};