From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id BD5D41FA00 for ; Mon, 22 Feb 2021 11:22:59 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 04/10] lei convert: auth directly from worker process Date: Mon, 22 Feb 2021 08:22:53 -0300 Message-Id: <20210222112259.32402-4-e@80x24.org> In-Reply-To: <20210222112259.32402-1-e@80x24.org> References: <20210222112155.32231-1-e@80x24.org> <20210222112259.32402-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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;