about summary refs log tree commit homepage
path: root/lib/PublicInbox/V1Writable.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-05-14 02:04:41 +0000
committerEric Wong <e@80x24.org>2019-05-14 02:05:55 +0000
commitfdfd7161a9257b70d65ab55dba4328b4960142d3 (patch)
treece3fe2b0a13c62931f8e4b039f3f73c38561a8dd /lib/PublicInbox/V1Writable.pm
parent7e2abe2d068367f2fcdf638a4482c953111df156 (diff)
downloadpublic-inbox-fdfd7161a9257b70d65ab55dba4328b4960142d3.tar.gz
Import initialization is a little strange from history, but we
also can't change it too much because it's technically a public
API which external code may rely on...

And we may need to support v1 repos indefinitely.  This should
make it easier to write tests for both formats.
Diffstat (limited to 'lib/PublicInbox/V1Writable.pm')
-rw-r--r--lib/PublicInbox/V1Writable.pm34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/PublicInbox/V1Writable.pm b/lib/PublicInbox/V1Writable.pm
new file mode 100644
index 00000000..6ca5db4a
--- /dev/null
+++ b/lib/PublicInbox/V1Writable.pm
@@ -0,0 +1,34 @@
+# Copyright (C) 2019 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+
+# This interface wraps PublicInbox::Import and makes it closer
+# to V2Writable
+# Used to write to V1 inboxes (see L<public-inbox-v1-format(5)>).
+package PublicInbox::V1Writable;
+use strict;
+use warnings;
+use base qw(PublicInbox::Import);
+use PublicInbox::InboxWritable;
+
+sub new {
+        my ($class, $ibx, $creat) = @_;
+        my $dir = $ibx->{mainrepo} or die "no mainrepo in inbox\n";
+        unless (-d $dir) {
+                if ($creat) {
+                        PublicInbox::Import::init_bare($dir);
+                } else {
+                        die "$dir does not exist\n";
+                }
+        }
+        $ibx = PublicInbox::InboxWritable->new($ibx);
+        $class->SUPER::new(undef, undef, undef, $ibx);
+}
+
+sub init_inbox {
+        my ($self, $partitions, $skip_epoch, $skip_artnum) = @_;
+        # TODO: honor skip_artnum
+        my $dir = $self->{-inbox}->{mainrepo} or die "no mainrepo in inbox\n";
+        PublicInbox::Import::init_bare($dir);
+}
+
+1;