unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] lei_to_mail: update some comments and style
Date: Tue, 30 Mar 2021 12:23:54 +0500	[thread overview]
Message-ID: <20210330072354.7994-1-e@80x24.org> (raw)

Note that update_kw_maybe is critical in preventing accidental
data loss with default "lei q --output" behavior.

Also avoid treating (proposed) MH support as lock-free, since
appears to lack specifications for locking and be even worse
than mbox* in that regard...
---
 lib/PublicInbox/LeiToMail.pm | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/lib/PublicInbox/LeiToMail.pm b/lib/PublicInbox/LeiToMail.pm
index 847e5cb9..4c33c752 100644
--- a/lib/PublicInbox/LeiToMail.pm
+++ b/lib/PublicInbox/LeiToMail.pm
@@ -227,24 +227,25 @@ sub _mbox_write_cb ($$) {
 sub update_kw_maybe ($$$$) {
 	my ($lei, $lse, $eml, $kw) = @_;
 	return unless $lse;
-	my $x = $lse->kw_changed($eml, $kw);
+	my $lse_oids = $lse->kw_changed($eml, $kw);
 	my $vmd = { kw => $kw };
-	if ($x) {
+	if ($lse_oids) { # already in lei/store
+		$lei->{sto}->ipc_do('set_eml', $eml, $vmd);
+	} elsif (my $xoids = $lei->{ale}->xoids_for($eml)) {
+		# it's in an external, only set kw, here
+		$lei->{sto}->ipc_do('set_xvmd', $xoids, $eml, $vmd);
+	} else { # never-before-seen, import the whole thing
+		# XXX this is critical in protecting against accidental
+		# data loss without --augment
 		$lei->{sto}->ipc_do('set_eml', $eml, $vmd);
-	} elsif (!defined($x)) {
-		if (my $xoids = $lei->{ale}->xoids_for($eml)) {
-			$lei->{sto}->ipc_do('set_xvmd', $xoids, $eml, $vmd);
-		} else {
-			$lei->{sto}->ipc_do('set_eml', $eml, $vmd);
-		}
 	}
 }
 
 sub _augment_or_unlink { # maildir_each_eml cb
 	my ($f, $kw, $eml, $lei, $lse, $mod, $shard, $unlink) = @_;
 	if ($mod) {
-		# can't get dirent.d_ino w/ pure Perl, so we extract the OID
-		# if it looks like one:
+		# can't get dirent.d_ino w/ pure Perl readdir, so we extract
+		# the OID if it looks like one instead of doing stat(2)
 		my $hex = $f =~ m!\b([a-f0-9]{40,})[^/]*\z! ?
 				$1 : sha256_hex($f);
 		my $recno = hex(substr($hex, 0, 8));
@@ -564,7 +565,7 @@ sub do_post_auth {
 		my $shard = $self->{-wq_worker_nr};
 		if (my $net = $lei->{net}) {
 			$net->{shard_info} = [ $mod, $shard ];
-		} else { # Maildir (MH?)
+		} else { # Maildir
 			$self->{shard_info} = [ $mod, $shard ];
 		}
 		$aug = '+'; # incr_post_augment
@@ -595,7 +596,7 @@ sub ipc_atfork_child {
 }
 
 sub lock_free {
-	$_[0]->{base_type} =~ /\A(?:maildir|mh|imap|jmap)\z/ ? 1 : 0;
+	$_[0]->{base_type} =~ /\A(?:maildir|imap|jmap)\z/ ? 1 : 0;
 }
 
 sub poke_dst {

                 reply	other threads:[~2021-03-30  7:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210330072354.7994-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).