]> Sergey Matveev's repositories - public-inbox.git/blob - xt/over-fsck.perl
solver_git: more descriptive error for "git apply" failures
[public-inbox.git] / xt / over-fsck.perl
1 #!perl -w
2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # unstable dev script, chasing a bug which may be in LeiSavedSearch->is_dup
5 use v5.12;
6 use Data::Dumper;
7 use PublicInbox::OverIdx;
8 @ARGV == 1 or die "Usage: $0 /path/to/over.sqlite3\n";
9 my $over = PublicInbox::OverIdx->new($ARGV[0]);
10 my $dbh = $over->dbh;
11 $dbh->do('PRAGMA mmap_size = '.(2 ** 48));
12 my $num = 0;
13 my ($err, $none, $nr, $ids);
14 $Data::Dumper::Useqq = $Data::Dumper::Sortkeys = 1;
15 do {
16         $ids = $over->ids_after(\$num);
17         $nr += @$ids;
18         for my $n (@$ids) {
19                 my $smsg = $over->get_art($n);
20                 if (!$smsg) {
21                         warn "#$n article missing\n";
22                         ++$err;
23                         next;
24                 }
25                 my $exp = $smsg->{blob};
26                 if ($exp eq '') {
27                         ++$none if $smsg->{bytes};
28                         next;
29                 }
30                 my $xr3 = $over->get_xref3($n, 1);
31                 my $found;
32                 for my $r (@$xr3) {
33                         $r->[2] = unpack('H*', $r->[2]);
34                         $found = 1 if $r->[2] eq $exp;
35                 }
36                 if (!$found) {
37                         warn Dumper([$smsg, $xr3 ]);
38                         ++$err;
39                 }
40         }
41 } while (@$ids);
42 warn "$none/$nr had no blob (external?)\n" if $none;
43 warn "$err errors\n" if $err;
44 exit($err ? 1 : 0);