]> Sergey Matveev's repositories - public-inbox.git/commitdiff
net_reader: fix single NNTP article fetch, test ranges
authorEric Wong <e@80x24.org>
Sun, 19 Sep 2021 12:50:29 +0000 (12:50 +0000)
committerEric Wong <e@80x24.org>
Sun, 19 Sep 2021 19:52:58 +0000 (19:52 +0000)
While NNTP ranges was already working, fetching a single message
was broken.  We'll also simplify the code a bit and ensure
incremental synchronization is ignored when ranges are
specified.

lib/PublicInbox/NetReader.pm
t/lei-import-nntp.t
t/uri_nntps.t

index 30b8f810d8fd4fa17653733536973446d022ddee..236e824cd26d48ec2326b97455b139d0b5841a65 100644 (file)
@@ -725,21 +725,24 @@ sub _nntp_fetch_all ($$$) {
                my $msg = ndump($nn->message);
                return "E: GROUP $group <$sec> $msg";
        }
+       (defined($num_a) && defined($num_b) && $num_a > $num_b) and
+               return "E: $uri: backwards range: $num_a > $num_b";
 
        # IMAPTracker is also used for tracking NNTP, UID == article number
        # LIST.ACTIVE can get the equivalent of UIDVALIDITY, but that's
        # expensive.  So we assume newsgroups don't change:
        my ($itrk, $l_art) = itrk_last($self, $uri);
 
-       # allow users to specify articles to refetch
-       # cf. https://tools.ietf.org/id/draft-gilman-news-url-01.txt
-       # nntp://example.com/inbox.foo/$num_a-$num_b
-       $beg = $num_a if defined($num_a) && $num_a < $beg;
-       $end = $num_b if defined($num_b) && $num_b < $end;
-       if (defined $l_art) {
+       if (defined($l_art) && !defined($num_a)) {
                return if $l_art >= $end; # nothing to do
                $beg = $l_art + 1;
        }
+       # allow users to specify articles to refetch
+       # cf. https://tools.ietf.org/id/draft-gilman-news-url-01.txt
+       # nntp://example.com/inbox.foo/$num_a-$num_b
+       $beg = $num_a if defined($num_a) && $num_a > $beg && $num_a <= $end;
+       $end = $num_b if defined($num_b) && $num_b >= $beg && $num_b < $end;
+       $end = $beg if defined($num_a) && !defined($num_b);
        my ($err, $art, $last_art, $kw); # kw stays undef, no keywords in NNTP
        unless ($self->{quiet}) {
                warn "# $uri fetching ARTICLE $beg..$end\n";
index f2c3540624290f6e0dc170325448bd2b4a502d7d..1eb41e0ed2f9425d60333c46792f8781ba5a031a 100644 (file)
@@ -37,5 +37,31 @@ test_lei({ tmpdir => $tmpdir }, sub {
        ok(-s $f, 'mail_sync exists tracked for redundant imports');
        lei_ok 'ls-mail-sync';
        like($lei_out, qr!\A\Q$url\E\n\z!, 'ls-mail-sync output as-expected');
+
+       ok(!lei(qw(import), "$url/12-1"), 'backwards range rejected');
+
+       # new home
+       local $ENV{HOME} = "$tmpdir/h2";
+       lei_ok(qw(ls-mail-source -l), $url);
+       my $ls = json_utf8->decode($lei_out);
+       my ($high, $low) = @{$ls->[0]}{qw(high low)};
+       ok($high > $low, 'high > low');
+
+       my $end = $high - 1;
+       lei_ok qw(import), "$url/$high";
+       lei_ok qw(q z:0..); my $one = json_utf8->decode($lei_out);
+       pop @$one; # trailing null
+       is(scalar(@$one), 1, 'only 1 result');
+
+       local $ENV{HOME} = "$tmpdir/h3";
+       lei_ok qw(import), "$url/$low-$end";
+       lei_ok qw(q z:0..); my $start = json_utf8->decode($lei_out);
+       pop @$start; # trailing null
+       is(scalar(@$start), scalar(map { $_ } ($low..$end)),
+               'range worked as expected');
+       my %seen;
+       for (@$start, @$one) {
+               is($seen{$_->{blob}}++, 0, "blob $_->{blob} seen once");
+       }
 });
 done_testing;
index babd8088d7ea5492086c79178af3a880594a3504..6b123a9b0d7a276b7722d05fc1d03ef5034f11ef 100644 (file)
@@ -37,4 +37,7 @@ is(PublicInbox::URInntps->new('nntps://0:563/')->canonical->as_string,
 $uri = PublicInbox::URInntps->new('nntps://NSA:Hunter2@0/inbox');
 is($uri->userinfo, 'NSA:Hunter2', 'userinfo accepted w/ pass');
 
+$uri = PublicInbox::URInntps->new('nntps://NSA:Hunter2@0/inbox.test/9-10');
+is_deeply([$uri->group], [ 'inbox.test', 9, 10 ], 'ranges work');
+
 done_testing;