user/dev discussion of public-inbox itself
 help / color / Atom feed
86b4eb5c72e67b74a3474b1aee2030e3d3b71cec blob 3838 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
 
# Copyright (C) 2014-2018 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict;
use warnings;
use Test::More;
use PublicInbox::Config;
use File::Temp qw/tempdir/;
require './t/common.perl';
my $tmpdir = tempdir('pi-init-XXXXXX', TMPDIR => 1, CLEANUP => 1);
use constant pi_init => 'blib/script/public-inbox-init';
use PublicInbox::Import;
use File::Basename;
open my $null, '>>', '/dev/null';
my $rdr = { 2 => fileno($null) };
sub quiet_fail {
	my ($cmd, $msg) = @_;
	# run_die doesn't take absolute paths:
	my $path = $ENV{PATH};
	if (index($cmd->[0], '/') >= 0) {
		my ($dir, $base) = ($cmd->[0] =~ m!\A(.+)/([^/]+)\z!);
		$path = "$dir:$path";
		$cmd->[0] = $base;
	}
	local $ENV{PATH} = $path;
	eval { PublicInbox::Import::run_die($cmd, undef, $rdr) };
	isnt($@, '', $msg);
}

{
	local $ENV{PI_DIR} = "$tmpdir/.public-inbox/";
	my $cfgfile = "$ENV{PI_DIR}/config";
	my @cmd = (pi_init, 'blist', "$tmpdir/blist",
		   qw(http://example.com/blist blist@example.com));
	is(system(@cmd), 0, 'public-inbox-init OK');

	is(read_indexlevel('blist'), '', 'indexlevel unset by default');

	ok(-e $cfgfile, "config exists, now");
	is(system(@cmd), 0, 'public-inbox-init OK (idempotent)');

	chmod 0666, $cfgfile or die "chmod failed: $!";
	@cmd = (pi_init, 'clist', "$tmpdir/clist",
		   qw(http://example.com/clist clist@example.com));
	is(system(@cmd), 0, 'public-inbox-init clist OK');
	is((stat($cfgfile))[2] & 07777, 0666, "permissions preserved");

	@cmd = (pi_init, 'clist', '-V2', "$tmpdir/clist",
		   qw(http://example.com/clist clist@example.com));
	quiet_fail(\@cmd, 'attempting to init V2 from V1 fails');
}

SKIP: {
	foreach my $mod (qw(DBD::SQLite Search::Xapian::WritableDatabase)) {
		eval "require $mod";
		skip "$mod missing for v2", 2 if $@;
	}
	require_git(2.6, 1) or skip "git 2.6+ required", 2;
	local $ENV{PI_DIR} = "$tmpdir/.public-inbox/";
	my $cfgfile = "$ENV{PI_DIR}/config";
	my @cmd = (pi_init, '-V2', 'v2list', "$tmpdir/v2list",
		   qw(http://example.com/v2list v2list@example.com));
	is(system(@cmd), 0, 'public-inbox-init -V2 OK');
	ok(-d "$tmpdir/v2list", 'v2list directory exists');
	ok(-f "$tmpdir/v2list/msgmap.sqlite3", 'msgmap exists');
	ok(-d "$tmpdir/v2list/all.git", 'catch-all.git directory exists');
	@cmd = (pi_init, 'v2list', "$tmpdir/v2list",
		   qw(http://example.com/v2list v2list@example.com));
	is(system(@cmd), 0, 'public-inbox-init is idempotent');
	ok(! -d "$tmpdir/public-inbox" && !-d "$tmpdir/objects",
		'idempotent invocation w/o -V2 does not make inbox v1');
	is(read_indexlevel('v2list'), '', 'indexlevel unset by default');

	@cmd = (pi_init, 'v2list', "-V1", "$tmpdir/v2list",
		   qw(http://example.com/v2list v2list@example.com));
	quiet_fail(\@cmd, 'initializing V2 as V1 fails');

	foreach my $lvl (qw(medium basic)) {
		@cmd = (pi_init, "v2$lvl", '-V2', '-L', $lvl,
			"$tmpdir/v2$lvl", "http://example.com/v2$lvl",
			"v2$lvl\@example.com");
		is(system(@cmd), 0, "-init -L $lvl");
		is(read_indexlevel("v2$lvl"), $lvl, "indexlevel set to '$lvl'");
	}

	# loop for idempotency
	for (1..2) {
		@cmd = (pi_init, '-V2', '-S1', 'skip1', "$tmpdir/skip1",
			   qw(http://example.com/skip1 skip1@example.com));
		is(system(@cmd), 0, "--skip 1");
		my $gits = [ glob("$tmpdir/skip1/git/*.git") ];
		is_deeply(["$tmpdir/skip1/git/1.git"], $gits, 'skip OK');
	}


	@cmd = (pi_init, '-V2', '--skip=2', 'skip2', "$tmpdir/skip2",
		   qw(http://example.com/skip2 skip2@example.com));
	is(system(@cmd), 0, "--skip 2");
	my $gits = [ glob("$tmpdir/skip2/git/*.git") ];
	is_deeply(["$tmpdir/skip2/git/2.git"], $gits, 'skipping 2 works, too');
}

done_testing();

sub read_indexlevel {
	my ($inbox) = @_;
	local $ENV{GIT_CONFIG} = "$ENV{PI_DIR}/config";
	chomp(my $lvl = `git config publicinbox.$inbox.indexlevel`);
	$lvl;
}
debug log:

solving 86b4eb5 ...
found 86b4eb5 in https://80x24.org/public-inbox.git

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror http://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.org/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox