user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH] lei_to_mail: update some comments and style
@ 2021-03-30  7:23 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2021-03-30  7:23 UTC (permalink / raw)
  To: meta

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 {

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-30  7:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-30  7:23 [PATCH] lei_to_mail: update some comments and style Eric Wong

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ http://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git