$self;
}
+sub assert_usable_dir {
+ my ($self) = @_;
+ my $dir = $self->{inboxdir};
+ return $dir if defined($dir) && $dir ne '';
+ die "no inboxdir defined for $self->{name}\n";
+}
+
sub init_inbox {
my ($self, $shards, $skip_epoch, $skip_artnum) = @_;
# TODO: honor skip_artnum
my $v = $self->{version} || 1;
if ($v == 1) {
- my $dir = $self->{inboxdir} or die "no inboxdir in inbox\n";
+ my $dir = assert_usable_dir($self);
PublicInbox::Import::init_bare($dir);
} else {
my $v2w = importer($self);
# $creat may be any true value, or 0/undef. A hashref is true,
# and $creat->{nproc} may be set to an integer
my ($class, $v2ibx, $creat) = @_;
- my $dir = $v2ibx->{inboxdir} or die "no inboxdir in inbox\n";
+ $v2ibx = PublicInbox::InboxWritable->new($v2ibx);
+ my $dir = $v2ibx->assert_usable_dir;
unless (-d $dir) {
if ($creat) {
require File::Path;
die "$dir does not exist\n";
}
}
-
- $v2ibx = PublicInbox::InboxWritable->new($v2ibx);
$v2ibx->umask_prepare;
my $xpfx = "$dir/xap" . PublicInbox::Search::SCHEMA_VERSION;
}
defined $dst or do_exit(67); # EX_NOUSER 5.1.1 user unknown
}
-$dst->{inboxdir} or do_exit(67);
+
$dst = PublicInbox::InboxWritable->new($dst);
+eval { $dst->assert_usable_dir };
+do_exit(67) if $@;
# pre-check, MDA has stricter rules than an importer might;
if ($precheck && !PublicInbox::MDA->precheck($simple, $dst->{address})) {
$im->done;
is(undef, $im->checkpoint, 'checkpoint works after ->done');
$im->checkpoint;
+
+my $nogit = PublicInbox::Git->new("$dir/non-existent/dir");
+eval {
+ my $nope = PublicInbox::Import->new($nogit, 'nope', 'no@example.com');
+ $nope->add($mime);
+};
+ok($@, 'Import->add fails on non-existent dir');
+
done_testing();
$im->done;
}
+my $tmp = {
+ inboxdir => "$inboxdir/non-existent/subdir",
+ name => 'nope',
+ version => 2,
+ -primary_address => 'test@example.com',
+};
+eval {
+ my $nope = PublicInbox::V2Writable->new($tmp);
+ $nope->add($mime);
+};
+ok($@, 'V2Writable fails on non-existent dir');
+
done_testing();