]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/V1Writable.pm
v1writable: new wrapper which is closer to v2writable
[public-inbox.git] / lib / PublicInbox / V1Writable.pm
1 # Copyright (C) 2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # This interface wraps PublicInbox::Import and makes it closer
5 # to V2Writable
6 # Used to write to V1 inboxes (see L<public-inbox-v1-format(5)>).
7 package PublicInbox::V1Writable;
8 use strict;
9 use warnings;
10 use base qw(PublicInbox::Import);
11 use PublicInbox::InboxWritable;
12
13 sub new {
14         my ($class, $ibx, $creat) = @_;
15         my $dir = $ibx->{mainrepo} or die "no mainrepo in inbox\n";
16         unless (-d $dir) {
17                 if ($creat) {
18                         PublicInbox::Import::init_bare($dir);
19                 } else {
20                         die "$dir does not exist\n";
21                 }
22         }
23         $ibx = PublicInbox::InboxWritable->new($ibx);
24         $class->SUPER::new(undef, undef, undef, $ibx);
25 }
26
27 sub init_inbox {
28         my ($self, $partitions, $skip_epoch, $skip_artnum) = @_;
29         # TODO: honor skip_artnum
30         my $dir = $self->{-inbox}->{mainrepo} or die "no mainrepo in inbox\n";
31         PublicInbox::Import::init_bare($dir);
32 }
33
34 1;