* [PATCH 9/9] lei_overview: start implementing format detection
2021-01-19 9:34 7% [PATCH 0/9] lei bugfixes and error handling Eric Wong
@ 2021-01-19 9:34 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2021-01-19 9:34 UTC (permalink / raw)
To: meta
We'll need it for IMAP support, at least. Proper mbox family
detection will be expensive, so deal with it later.
---
lib/PublicInbox/LeiOverview.pm | 17 ++++++++++++++++-
t/lei.t | 2 ++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/lib/PublicInbox/LeiOverview.pm b/lib/PublicInbox/LeiOverview.pm
index a7021b03..dcc3088b 100644
--- a/lib/PublicInbox/LeiOverview.pm
+++ b/lib/PublicInbox/LeiOverview.pm
@@ -38,6 +38,21 @@ sub ovv_out_lk_cancel ($) {
unlink(delete($self->{lock_path}));
}
+sub detect_fmt ($$) {
+ my ($lei, $dst) = @_;
+ if ($dst =~ m!\A([:/]+://)!) {
+ $lei->fail("$1 support not implemented, yet\n");
+ } elsif (!-e $dst) {
+ 'maildir'; # the default
+ } elsif (-f _ || -p _) {
+ $lei->fail("unable to determine mbox family of $dst\n");
+ } elsif (-d _) { # TODO: MH?
+ 'maildir';
+ } else {
+ $lei->fail("unable to determine format of $dst\n");
+ }
+}
+
sub new {
my ($class, $lei) = @_;
my $opt = $lei->{opt};
@@ -54,7 +69,7 @@ sub new {
}
$fmt //= 'json' if $dst eq '/dev/stdout';
- $fmt //= 'maildir';
+ $fmt //= detect_fmt($lei, $dst) or return;
if (index($dst, '://') < 0) { # not a URL, so assume path
$dst = File::Spec->canonpath($dst);
diff --git a/t/lei.t b/t/lei.t
index 8bb4e439..64cb5f0e 100644
--- a/t/lei.t
+++ b/t/lei.t
@@ -232,6 +232,8 @@ my $test_external = sub {
my @res = $cat->();
is_deeply(\@res, [], "clobber w/o --augment $sfx");
}
+ ok(!$lei->('q', '-o', "$home/mbox", 's:nope'),
+ 'fails if mbox format unspecified');
};
my $test_lei_common = sub {
^ permalink raw reply related [relevance 7%]
* [PATCH 0/9] lei bugfixes and error handling
@ 2021-01-19 9:34 7% Eric Wong
2021-01-19 9:34 7% ` [PATCH 9/9] lei_overview: start implementing format detection Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2021-01-19 9:34 UTC (permalink / raw)
To: meta
1/9 could have some potential when we start handling remotes,
3/9 seems necessary, unfortunately :<
4/9 helped find some bugs,
9/9 is incomplete, but that describes everything :<
Eric Wong (9):
lei q: start ->mset while query_prepare runs
lei q: fix SIGPIPE handling from lei2mail workers
lei q: do not spawn MUA early
lei: write daemon errors to the sock directory
lei q: fix augment of compressed mailboxes
lei_overview: do not write if $lei->{1} is gone
t/lei: fix double-running of socket test with oneshot
lei: test some likely errors due to misuse
lei_overview: start implementing format detection
lib/PublicInbox/LEI.pm | 22 ++++---
lib/PublicInbox/LeiOverview.pm | 25 ++++++--
lib/PublicInbox/LeiToMail.pm | 39 +++++++-----
lib/PublicInbox/LeiXSearch.pm | 105 +++++++++++++++++++++++----------
lib/PublicInbox/Spawn.pm | 2 +-
t/lei.t | 75 +++++++++++++++--------
t/lei_to_mail.t | 4 +-
xt/lei-sigpipe.t | 29 +++++----
8 files changed, 200 insertions(+), 101 deletions(-)
^ permalink raw reply [relevance 7%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-01-19 9:34 7% [PATCH 0/9] lei bugfixes and error handling Eric Wong
2021-01-19 9:34 7% ` [PATCH 9/9] lei_overview: start implementing format detection Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
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).