From 76689d2b939f3a36db406684b588eb5bec10955b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 22 Feb 2021 08:22:53 -0300 Subject: [PATCH] lei convert: auth directly from worker process Since this only has one worker, we can auth directly in the worker since the convert worker now has access to the script/lei {sock} for running "git credential". --- lib/PublicInbox/LeiConvert.pm | 20 +++++++++++--------- lib/PublicInbox/NetReader.pm | 16 +++++++++------- lib/PublicInbox/NetWriter.pm | 2 +- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/PublicInbox/LeiConvert.pm b/lib/PublicInbox/LeiConvert.pm index ba375772..3a714502 100644 --- a/lib/PublicInbox/LeiConvert.pm +++ b/lib/PublicInbox/LeiConvert.pm @@ -32,6 +32,10 @@ sub do_convert { # via wq_do my ($self) = @_; my $lei = $self->{lei}; my $in_fmt = $lei->{opt}->{'in-format'}; + my $mics; + if (my $nrd = $lei->{nrd}) { # may prompt user once + $nrd->{mics_cached} = $nrd->imap_common_init($lei); + } if (my $stdin = delete $self->{0}) { PublicInbox::MboxReader->$in_fmt($stdin, \&mbox_cb, $self); } @@ -120,16 +124,14 @@ sub call { # the main "lei convert" method require PublicInbox::MdirReader; } $self->{inputs} = \@inputs; - return convert_start($lei) if !$nrd; - - if (my $err = $nrd->errors) { - return $lei->fail($err); + if ($nrd) { + if (my $err = $nrd->errors) { + return $lei->fail($err); + } + $nrd->{quiet} = $opt->{quiet}; + $lei->{nrd} = $nrd; } - $nrd->{quiet} = $opt->{quiet}; - $lei->{nrd} = $nrd; - require PublicInbox::LeiAuth; - my $auth = $lei->{auth} = PublicInbox::LeiAuth->new($nrd); - $auth->auth_start($lei, \&convert_start, $lei); + convert_start($lei); } sub ipc_atfork_child { diff --git a/lib/PublicInbox/NetReader.pm b/lib/PublicInbox/NetReader.pm index 0956d5da..c29e09c1 100644 --- a/lib/PublicInbox/NetReader.pm +++ b/lib/PublicInbox/NetReader.pm @@ -423,14 +423,16 @@ sub _imap_fetch_all ($$$) { # uses cached auth info prepared by mic_for sub mic_get { - my ($self, $sec) = @_; - my $mic_arg = $self->{mic_arg}->{$sec}; - unless ($mic_arg) { - my $uri = ref $sec ? $sec : PublicInbox::URIimap->new($sec); - $sec = uri_section($uri); - $mic_arg = $self->{mic_arg}->{$sec} or - die "BUG: no Mail::IMAPClient->new arg for $sec"; + my ($self, $uri) = @_; + my $sec = uri_section($uri); + # see if caller saved result of imap_common_init + if (my $cached = $self->{mics_cached}) { + my $mic = $cached->{$sec}; + return $mic if $mic && $mic->IsConnected; + delete $cached->{$sec}; } + my $mic_arg = $self->{mic_arg}->{$sec} or + die "BUG: no Mail::IMAPClient->new arg for $sec"; if (defined(my $cb_name = $mic_arg->{Authcallback})) { if (ref($cb_name) ne 'CODE') { $mic_arg->{Authcallback} = $self->can($cb_name); diff --git a/lib/PublicInbox/NetWriter.pm b/lib/PublicInbox/NetWriter.pm index 89f8662e..c68b0669 100644 --- a/lib/PublicInbox/NetWriter.pm +++ b/lib/PublicInbox/NetWriter.pm @@ -28,7 +28,7 @@ sub imap_delete_all { my $uri = PublicInbox::URIimap->new($url); my $sec = $self->can('uri_section')->($uri); local $0 = $uri->mailbox." $sec"; - my $mic = $self->mic_get($sec) or die "E: not connected: $@"; + my $mic = $self->mic_get($uri) or die "E: not connected: $@"; $mic->select($uri->mailbox) or return; # non-existent if ($mic->delete_message('1:*')) { $mic->expunge; -- 2.44.0