From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 91FB51F560 for ; Sat, 30 Sep 2023 00:36:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1696034176; bh=XZ36ryfVeOvHcfrjSPSiV1VMg1qI6JZtYlBv+ygZk+g=; h=From:To:Subject:Date:In-Reply-To:References:From; b=POZk9X7PWlSe4zVExi+LdJQhQn48MWZzAz++todKEdQgXnAP4gxzJy+24apD63b/D aab4w20HHsAuNr470scrHuqGqAy2sELUpSoE2vM/q6Ln/133QBi+P3155JAtCPLWlt Ib9e+dLzzhOs9WOJv8UgeZZdR3Syl7hjytf+/Q8g= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/2] lei_input: always prefix `maildir:' internally Date: Sat, 30 Sep 2023 00:36:15 +0000 Message-Id: <20230930003616.3224311-2-e@80x24.org> In-Reply-To: <20230930003616.3224311-1-e@80x24.org> References: <20230930003616.3224311-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This allows us to reduce stats for `new' and `cur' subdirs of the Maildir and will also make it easier for us to support MH, v2, v1, and extindex directories as inputs. --- lib/PublicInbox/LeiInput.pm | 57 ++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/lib/PublicInbox/LeiInput.pm b/lib/PublicInbox/LeiInput.pm index b6c2b6bb..f88c5374 100644 --- a/lib/PublicInbox/LeiInput.pm +++ b/lib/PublicInbox/LeiInput.pm @@ -1,10 +1,9 @@ -# Copyright (C) 2021 all contributors +# Copyright (C) all contributors # License: AGPL-3.0+ # parent class for LeiImport, LeiConvert, LeiIndex package PublicInbox::LeiInput; -use strict; -use v5.10.1; +use v5.12; use PublicInbox::DS; use PublicInbox::Spawn qw(which popen_rd); use PublicInbox::InboxWritable qw(eml_from_path); @@ -181,10 +180,7 @@ sub input_path_url { } local $PublicInbox::DS::in_loop = 0 if $zsfx; # awaitpid $self->input_fh($ifmt, $mbl->{fh}, $input, @args); - } elsif (-d _ && (-d "$input/cur" || -d "$input/new")) { - return $lei->fail(<new; if (my $pmd = $self->{pmd}) { $mdr->maildir_each_file($input, @@ -259,6 +255,17 @@ sub prepare_http_input ($$$) { $self->{"-curl-$url"} = [ @curl_opt, $uri ]; # for handle_http_input } +sub add_dir ($$$$) { + my ($lei, $istate, $ifmt, $input) = @_; + if ($istate->{-may_sync}) { + $$input = "$ifmt:".$lei->abs_path($$input); + push @{$istate->{-sync}->{ok}}, $$input if $istate->{-sync}; + } else { + substr($$input, 0, 0) = "$ifmt:"; # prefix + } + push @{$istate->{$ifmt}}, $$input; +} + sub prepare_inputs { # returns undef on error my ($self, $lei, $inputs) = @_; my $in_fmt = $lei->{opt}->{'in-format'}; @@ -272,7 +279,8 @@ sub prepare_inputs { # returns undef on error push @{$sync->{no}}, '/dev/stdin' if $sync; } my $net = $lei->{net}; # NetWriter may be created by l2m - my (@f, @md); + my @f; + my $istate = { -sync => $sync, -may_sync => $may_sync }; # e.g. Maildir:/home/user/Mail/ or imaps://example.com/INBOX for my $input (@$inputs) { my $input_path = $input; @@ -292,11 +300,8 @@ sub prepare_inputs { # returns undef on error --in-format=$in_fmt and `$ifmt:' conflict } - if ($ifmt =~ /\A(?:maildir|mh)\z/i) { - push @{$sync->{ok}}, $input if $sync; - } else { - push @{$sync->{no}}, $input if $sync; - } + ($sync && $ifmt !~ /\A(?:maildir|mh)\z/i) and + push(@{$sync->{no}}, $input); my $devfd = $lei->path_to_fd($input_path) // return; if ($devfd >= 0 || (-f $input_path || -p _)) { require PublicInbox::MboxLock; @@ -304,11 +309,10 @@ sub prepare_inputs { # returns undef on error PublicInbox::MboxReader->reads($ifmt) or return $lei->fail("$ifmt not supported"); } elsif (-d $input_path) { - $ifmt eq 'maildir' or return + $ifmt eq 'maildir' or return # TODO v1/v2/ei $lei->fail("$ifmt not supported"); - $may_sync and $input = 'maildir:'. - $lei->abs_path($input_path); - push @md, $input; + $input = $input_path; + add_dir $lei, $istate, $ifmt, \$input; } elsif ($self->{missing_ok} && !-e _) { # for "lei rm-watch" on missing Maildir $may_sync and $input = 'maildir:'. @@ -345,12 +349,13 @@ $input is `eml', not --in-format=$in_fmt push @{$sync->{no}}, $input if $sync; push @f, $input; } elsif (-d "$input/new" && -d "$input/cur") { - if ($may_sync) { - $input = 'maildir:'. - $lei->abs_path($input); - push @{$sync->{ok}}, $input if $sync; - } - push @md, $input; + add_dir $lei, $istate, 'maildir', \$input; + } elsif (-e "$input/inbox.lock") { # TODO + $lei->fail('v2 inputs not yet supported (TODO)'); + #add_dir $lei, $istate, 'v2', \$input; + } elsif (-e "$input/ssoma.lock") { # TODO + $lei->fail('v1 inputs not yet supported (TODO)'); + #add_dir $lei, $istate, 'v1', \$input; } elsif ($self->{missing_ok} && !-e $input) { if ($lei->{cmd} eq 'p2q') { # will run "git format-patch" @@ -382,17 +387,17 @@ $input is `eml', not --in-format=$in_fmt $lei->{auth} //= PublicInbox::LeiAuth->new; $lei->{net} //= $net; } - if (scalar(@md)) { + if (my $md = $istate->{maildir}) { require PublicInbox::MdirReader; if ($self->can('pmdir_cb')) { require PublicInbox::LeiPmdir; $self->{pmd} = PublicInbox::LeiPmdir->new($lei, $self); } + grep(!m!\Amaildir:/!i, @$md) and die "BUG: @$md (no pfx)"; # start watching Maildirs ASAP if ($may_sync && $lei->{sto}) { - grep(!m!\Amaildir:/!i, @md) and die "BUG: @md (no pfx)"; - $lei->lms(1)->lms_write_prepare->add_folders(@md); + $lei->lms(1)->lms_write_prepare->add_folders(@$md); $lei->refresh_watches; } }