* [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 related [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
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).