From ef68ada3b207fdb511ebe6d33b072a84277e6cd6 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 5 Oct 2021 09:40:17 +0000 Subject: index: --reindex w/ --{since,until,before,after} This lets administrators reindex specific time ranges according to git "approxidate" formats. These arguments are passed directly to underlying git-log(1) invocations and may still reach into old epochs. Since these options rely on git committer dates (which we infer from the most recent Received: header), they are not guaranteed to be strictly tied to git history and it's possible to over/under-reindex some messages. It's probably not a major problem in practice, though; reindexing a few extra messages is generally harmless aside from some extra device wear. Since this currently relies on git-log, these options do not affect -extindex, yet. --- t/reindex-time-range.t | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 t/reindex-time-range.t (limited to 't/reindex-time-range.t') diff --git a/t/reindex-time-range.t b/t/reindex-time-range.t new file mode 100644 index 00000000..59f5c2aa --- /dev/null +++ b/t/reindex-time-range.t @@ -0,0 +1,58 @@ +# Copyright (C) all contributors +# License: AGPL-3.0+ +use strict; use v5.10.1; use PublicInbox::TestCommon; +require_mods qw(DBD::SQLite); +my $tmp = tmpdir(); +my $eml; +my $cb = sub { + my ($im, $ibx) = @_; + $eml //= eml_load 't/utf8.eml'; + for my $i (1..3) { + $eml->header_set('Message-ID', "<$i\@example.com>"); + my $d = "Thu, 01 Jan 1970 0$i:30:00 +0000"; + $eml->header_set('Date', $d); + $im->add($eml); + } +}; +my %ibx = map {; + "v$_" => create_inbox("v$_", version => $_, + indexlevel => 'basic', tmpdir => "$tmp/v$_", $cb); +} (1, 2); + +my $env = { TZ => 'UTC' }; +my ($out, $err); +for my $v (sort keys %ibx) { + my $opt = { -C => $ibx{$v}->{inboxdir}, 1 => \$out, 2 => \$err }; + + ($out, $err) = ('', ''); + run_script([ qw(-index -vv) ], $env, $opt); + is($?, 0, 'no error on initial index'); + + for my $x (qw(until before)) { + ($out, $err) = ('', ''); + run_script([ qw(-index --reindex -vv), + "--$x=1970-01-01T02:00:00Z" ], $env, $opt); + is($?, 0, "no error with --$x"); + like($err, qr! 1/1\b!, "$x only indexed one message"); + } + for my $x (qw(after since)) { + ($out, $err) = ('', ''); + run_script([ qw(-index --reindex -vv), + "--$x=1970-01-01T02:00:00Z" ], $env, $opt); + is($?, 0, "no error with --$x"); + like($err, qr! 2/2\b!, "$x only indexed one message"); + } + + ($out, $err) = ('', ''); + run_script([ qw(-index --reindex -vv) ], $env, $opt); + is($?, 0, 'no error on initial index'); + + for my $x (qw(since before after until)) { + ($out, $err) = ('', ''); + run_script([ qw(-index -v), "--$x=1970-01-01T02:00:00Z" ], + $env, $opt); + isnt($?, 0, "--$x fails on --reindex"); + } +} + +done_testing; -- cgit v1.2.3-24-ge0c7