1 # Copyright (C) 2015 all contributors <meta@public-inbox.org>
2 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
3 package PublicInbox::NewsGroup;
6 use Scalar::Util qw(weaken);
8 require PublicInbox::Msgmap;
9 require PublicInbox::GitCatFile;
12 my ($class, $name, $git_dir, $address) = @_;
13 $address = $address->[0] if ref($address);
19 $self->{domain} = ($address =~ /\@(\S+)\z/) ? $1 : 'localhost';
24 my ($self, $field) = @_;
25 Danga::Socket->AddTimer(30, sub { weaken($self->{$field}) });
30 $self->{gcf} ||= eval {
31 my $gcf = PublicInbox::GitCatFile->new($self->{git_dir});
33 # git repos may be repacked and old packs unlinked
34 defer_weaken($self, 'gcf');
40 my ($self, $check_only) = @_;
42 return eval { PublicInbox::Msgmap->new($self->{git_dir}) };
44 $self->{mm} ||= eval {
45 my $mm = PublicInbox::Msgmap->new($self->{git_dir});
47 # may be needed if we run low on handles
48 defer_weaken($self, 'mm');
55 $self->{search} ||= eval {
56 require PublicInbox::Search;
57 my $search = PublicInbox::Search->new($self->{git_dir});
59 # may be needed if we run low on handles
60 defer_weaken($self, 'search');
67 open my $fh, '<', "$self->{git_dir}/description" or return '';
68 my $desc = eval { local $/; <$fh> };
75 my ($self, $new) = @_;
76 $self->{address} = $new->{address};
77 $self->{domain} = $new->{domain};
78 if ($self->{git_dir} ne $new->{git_dir}) {
79 # new git_dir requires a new mm and gcf
80 $self->{mm} = $self->{gcf} = undef;
81 $self->{git_dir} = $new->{git_dir};