]> Sergey Matveev's repositories - public-inbox.git/blob - t/convert-compact.t
v2: respect core.sharedRepository in git configs
[public-inbox.git] / t / convert-compact.t
1 # Copyright (C) 2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 use strict;
4 use warnings;
5 use Test::More;
6 use File::Temp qw/tempdir/;
7 use PublicInbox::MIME;
8 my @mods = qw(DBD::SQLite Search::Xapian);
9 foreach my $mod (@mods) {
10         eval "require $mod";
11         plan skip_all => "$mod missing for convert-compact.t" if $@;
12 }
13 use PublicInbox::V2Writable;
14 use PublicInbox::Import;
15 my $tmpdir = tempdir('convert-compact-XXXXXX', TMPDIR => 1, CLEANUP => 1);
16 my $ibx = {
17         mainrepo => "$tmpdir/v1",
18         name => 'test-v1',
19         -primary_address => 'test@example.com',
20 };
21
22 ok(PublicInbox::Import::run_die([qw(git init --bare -q), $ibx->{mainrepo}]),
23         'initialized v1 repo');
24 ok(umask(077), 'set restrictive umask');
25 ok(PublicInbox::Import::run_die([qw(git) , "--git-dir=$ibx->{mainrepo}",
26         qw(config core.sharedRepository 0644)]), 'set sharedRepository');
27 $ibx = PublicInbox::Inbox->new($ibx);
28 my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
29 my $mime = PublicInbox::MIME->create(
30         header => [
31                 From => 'a@example.com',
32                 To => 'test@example.com',
33                 Subject => 'this is a subject',
34                 'Message-ID' => '<a-mid@b>',
35                 Date => 'Fri, 02 Oct 1993 00:00:00 +0000',
36         ],
37         body => "hello world\n",
38 );
39 ok($im->add($mime), 'added one message');
40 $im->done;
41 PublicInbox::SearchIdx->new($ibx, 1)->index_sync;
42
43 is(((stat("$ibx->{mainrepo}/public-inbox"))[2]) & 07777, 0755,
44         'sharedRepository respected for v1');
45 is(((stat("$ibx->{mainrepo}/public-inbox/msgmap.sqlite3"))[2]) & 07777, 0644,
46         'sharedRepository respected for v1 msgmap');
47 my @xdir = glob("$ibx->{mainrepo}/public-inbox/xap*/*");
48 foreach (@xdir) {
49         my @st = stat($_);
50         is($st[2] & 07777, -f _ ? 0644 : 0755,
51                 'sharedRepository respected on file after convert');
52 }
53
54 local $ENV{PATH} = "blib/script:$ENV{PATH}";
55 open my $err, '>>', "$tmpdir/err.log" or die "open: err.log $!\n";
56 open my $out, '>>', "$tmpdir/out.log" or die "open: out.log $!\n";
57 my $rdr = { 1 => fileno($out), 2 => fileno($err) };
58
59 my $cmd = [ 'public-inbox-compact', $ibx->{mainrepo} ];
60 ok(PublicInbox::Import::run_die($cmd, undef, $rdr), 'v1 compact works');
61
62 @xdir = glob("$ibx->{mainrepo}/public-inbox/xap*");
63 is(scalar(@xdir), 1, 'got one xapian directory after compact');
64 is(((stat($xdir[0]))[2]) & 07777, 0755,
65         'sharedRepository respected on v1 compact');
66
67 $cmd = [ 'public-inbox-convert', $ibx->{mainrepo}, "$tmpdir/v2" ];
68 ok(PublicInbox::Import::run_die($cmd, undef, $rdr), 'convert works');
69 @xdir = glob("$tmpdir/v2/xap*/*");
70 foreach (@xdir) {
71         my @st = stat($_);
72         is($st[2] & 07777, -f _ ? 0644 : 0755,
73                 'sharedRepository respected after convert');
74 }
75
76 $cmd = [ 'public-inbox-compact', "$tmpdir/v2" ];
77 my $env = { NPROC => 2 };
78 ok(PublicInbox::Import::run_die($cmd, $env, $rdr), 'v2 compact works');
79 $ibx->{mainrepo} = "$tmpdir/v2";
80 my $v2w = PublicInbox::V2Writable->new($ibx);
81 is($v2w->{partitions}, 1, "only one partition in compacted repo");
82
83 @xdir = glob("$tmpdir/v2/xap*/*");
84 foreach (@xdir) {
85         my @st = stat($_);
86         is($st[2] & 07777, -f _ ? 0644 : 0755,
87                 'sharedRepository respected after v2 compact');
88 }
89 is(((stat("$tmpdir/v2/msgmap.sqlite3"))[2]) & 07777, 0644,
90         'sharedRepository respected for v2 msgmap');
91
92 @xdir = (glob("$tmpdir/v2/git/*.git/objects/*/*"),
93          glob("$tmpdir/v2/git/*.git/objects/pack/*"));
94 foreach (@xdir) {
95         my @st = stat($_);
96         is($st[2] & 07777, -f _ ? 0444 : 0755,
97                 'sharedRepository respected after v2 compact');
98 }
99
100 done_testing();