From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 3A4611F452 for ; Tue, 28 Nov 2023 17:37:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1701193022; bh=+r3+J7hOMr3XZhzkTa16tYz0h5KxPBSO6OCNwsvucPg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nDiR4jnwXgIvjuJtlfqLF6QzjSEQFPaJ7+zo1Lg7Q59S0gsJMynngj/Xs1dzJZrF1 clKgHI5/0LXbkGRIV3e/r+ZM91SB2xEwPMyHAwHdpvtOom4ReCNrcwxpMrC1OyjsVb xleR7BuCSMuY3fbHofy9DRCMFHiyNE7yMDhzNemM= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/4] lei q: fix --no-import-before completion + docs Date: Tue, 28 Nov 2023 17:36:58 +0000 Message-ID: <20231128173701.1472101-2-e@80x24.org> In-Reply-To: <20231128173701.1472101-1-e@80x24.org> References: <20231128173701.1472101-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: --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 | 5 +++-- lib/PublicInbox/LEI.pm | 1 + t/lei-q-kw.t | 19 ++++++++++++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Documentation/lei-q.pod b/Documentation/lei-q.pod index 4862ce78..95f3f702 100644 --- a/Documentation/lei-q.pod +++ b/Documentation/lei-q.pod @@ -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 diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index 86b71fcd..a89bdc51 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -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' ], diff --git a/t/lei-q-kw.t b/t/lei-q-kw.t index 06e1df6c..63e46037 100644 --- a/t/lei-q-kw.t +++ b/t/lei-q-kw.t @@ -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 = { '' => eml_load('t/plack-qp.eml'), '' => 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'), ''; + 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]; } };