1 # Copyright (C) 2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use PublicInbox::TestCommon;
8 require_mods(qw(DBD::SQLite));
9 use Cwd qw(abs_path); # we need this since we chdir below
10 local $ENV{HOME} = abs_path('t');
11 my $purge = abs_path('blib/script/public-inbox-purge');
12 my ($tmpdir, $for_destroy) = tmpdir();
13 use_ok 'PublicInbox::V2Writable';
14 my $inboxdir = "$tmpdir/v2";
15 my $ibx = PublicInbox::Inbox->new({
16 inboxdir => $inboxdir,
17 name => 'test-v2purge',
19 -primary_address => 'test@example.com',
20 indexlevel => 'basic',
26 Subject: this is a subject
28 Date: Fri, 02 Oct 1993 00:00:00 +0000
34 my $cfgfile = "$tmpdir/config";
35 local $ENV{PI_CONFIG} = $cfgfile;
36 open my $cfg_fh, '>', $cfgfile or die "open: $!";
38 my $v2w = PublicInbox::V2Writable->new($ibx, {nproc => 1});
39 my $mime = PublicInbox::MIME->new($raw);
40 ok($v2w->add($mime), 'add message to be purged');
43 # failing cases, first:
44 my $in = "$raw\nMOAR\n";
45 my ($out, $err) = ('', '');
46 my $opt = { 0 => \$in, 1 => \$out, 2 => \$err };
47 ok(run_script([$purge, '-f', $inboxdir], undef, $opt), 'purge -f OK');
50 ok(!run_script([$purge, $inboxdir], undef, $opt), 'mismatch fails without -f');
51 is($? >> 8, 1, 'missed purge exits with 1');
55 ok(run_script([$purge, $inboxdir], undef, $opt), 'match OK');
56 like($out, qr/\b[a-f0-9]{40,}/m, 'removed commit noted');
58 # add (old) vger filter to config file
59 print $cfg_fh <<EOF or die "print $!";
60 [publicinbox "test-v2purge"]
62 address = test\@example.com
64 filter = PublicInbox::Filter::Vger
66 close $cfg_fh or die "close: $!";
68 ok($v2w->add($mime), 'add vger-signatured message to be purged');
71 my $pre_scrub = $raw . <<'EOF';
74 To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
75 the body of a message to majordomo@vger.kernel.org
76 More majordomo info at http://vger.kernel.org/majordomo-info.html
77 Please read the FAQ at http://www.tux.org/lkml/
81 ok(chdir('/'), "chdir / OK for --all test");
82 $opt->{0} = \$pre_scrub;
83 ok(run_script([$purge, '--all'], undef, $opt), 'scrub purge OK');
84 like($out, qr/\b[a-f0-9]{40,}/m, 'removed commit noted');
85 # diag "out: $out"; diag "err: $err";
88 ok(!run_script([$purge, '--all' ], undef, $opt),
89 'scrub purge not idempotent without -f');
90 # diag "out: $out"; diag "err: $err";