]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
lei q: fix --no-import-before completion + docs
authorEric Wong <e@80x24.org>
Tue, 28 Nov 2023 17:36:58 +0000 (17:36 +0000)
committerEric Wong <e@80x24.org>
Wed, 29 Nov 2023 02:13:29 +0000 (02:13 +0000)
--no-import-before skips importing entire messages, not just
keywords, so it can cause permanent data loss if -o is pointed
to precious data.

Documentation/lei-q.pod
lib/PublicInbox/LEI.pm
t/lei-q-kw.t

index 4862ce78b7093541a3a6c5a15d08a47f35b4729a..95f3f70289a1428dfa055d852f89d9305c86e338 100644 (file)
@@ -108,8 +108,9 @@ Augment output destination instead of clobbering it.
 
 =item --no-import-before
 
-Do not import keywords before writing to an existing output
-destination.
+Do not import messages before writing to an existing output destination.
+Be certain you do not need existing data in your output before using
+this, it permanently erases data unless C<--augment> is used.
 
 =item --threads
 
index 86b71fcd6931b32f5d875a21426664a0da7da4d4..a89bdc5155ae3416980c5f1ee16c8a18b369fe48 100644 (file)
@@ -353,6 +353,7 @@ my %OPTDESC = (
 'no-torsocks' => 'alias for --torsocks=no',
 'save!' =>  "do not save a search for `lei up'",
 'import-remote!' => 'do not memoize remote messages into local store',
+'import-before!' => 'do not import before writing to output (DANGEROUS)',
 
 'type=s' => [ 'any|mid|git', 'disambiguate type' ],
 
index 06e1df6cab572533784553c12ff649e29a1de150..63e4603786e16b5753de085ac9d042c74f7b3e31 100644 (file)
@@ -9,6 +9,8 @@ use IO::Compress::Gzip qw(gzip);
 use PublicInbox::MboxReader;
 use PublicInbox::LeiToMail;
 use PublicInbox::Spawn qw(popen_rd);
+use File::Path qw(make_path);
+use PublicInbox::IO qw(write_file);
 my $exp = {
        '<qp@example.com>' => eml_load('t/plack-qp.eml'),
        '<testmessage@example.com>' => eml_load('t/utf8.eml'),
@@ -42,6 +44,19 @@ lei_ok(qw(q -o), "maildir:$o", qw(m:qp@example.com));
 @fn = glob("$o/cur/*:2,S");
 is(scalar(@fn), 1, "`seen' flag (but not `replied') set on Maildir file");
 
+{
+       $o = "$ENV{HOME}/dst-existing";
+       make_path(map { "$o/$_" } qw(new cur tmp));
+       my $bp = eml_load('t/data/binary.patch');
+       write_file '>', "$o/cur/binary-patch:2,S", $bp->as_string;
+       lei_ok qw(q --no-import-before m:qp@example.com -o), $o;
+       my @g = glob("$o/*/*");
+       is scalar(@g), 1, 'only newly imported message left';
+       is eml_load($g[0])->header_raw('Message-ID'), '<qp@example.com>';
+       lei qw(q m:binary-patch-test@example);
+       is $lei_out, "[null]\n", 'old message not imported';
+}
+
 SKIP: {
        $o = "$ENV{HOME}/fifo";
        mkfifo($o, 0600) or skip("mkfifo not supported: $!", 1);
@@ -80,9 +95,7 @@ my $write_file = sub {
        if ($_[0] =~ /\.gz\z/) {
                gzip(\($_[1]), $_[0]) or BAIL_OUT 'gzip';
        } else {
-               open my $fh, '>', $_[0] or BAIL_OUT $!;
-               print $fh $_[1] or BAIL_OUT $!;
-               close $fh or BAIL_OUT;
+               write_file '>', $_[0], $_[1];
        }
 };