]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei: allow more mbox inode types
authorEric Wong <e@80x24.org>
Wed, 20 Jan 2021 05:04:43 +0000 (14:04 +0900)
committerEric Wong <e@80x24.org>
Thu, 21 Jan 2021 03:29:16 +0000 (03:29 +0000)
We may attempt to write an mbox to any terminal, block, or
character device, not just regular files and FIFOs/pipes.
The only thing that is known to not work is a directory.

Sockets may be possible with some OSes (e.g. Plan 9) or
filesystems.  This fixes t/lei.t on FreeBSD 11.x

lib/PublicInbox/LeiOverview.pm
lib/PublicInbox/LeiToMail.pm
t/lei.t

index dcc3088ba8f35e4b45fdf8eefffbb8b6c6f5bb51..cab2b055a5969347d0b55b64db155c7174342baa 100644 (file)
@@ -42,12 +42,10 @@ 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 (!-e $dst || -d _) {
+               'maildir'; # the default TODO: MH?
        } 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");
        }
index 49b5c8ab4cbdb3cb04480725dee6e7473c38cbfd..9d9b57486ecda64c963a071a29b5e6648a734923 100644 (file)
@@ -343,8 +343,8 @@ sub new {
                                "$dst exists and is not a directory\n";
                $lei->{ovv}->{dst} = $dst .= '/' if substr($dst, -1) ne '/';
        } elsif (substr($fmt, 0, 4) eq 'mbox') {
-               -e $dst && !-f _ && !-p _ and die
-                               "$dst exists and is not a regular file\n";
+               (-d $dst || (-e _ && !-w _)) and die
+                       "$dst exists and is not a writable file\n";
                $self->can("eml2$fmt") or die "bad mbox --format=$fmt\n";
                $self->{base_type} = 'mbox';
        } else {
diff --git a/t/lei.t b/t/lei.t
index 64cb5f0ef55378d4e4f9f5fb4ef689d304a3cf0e..d49dc01aac1a4bdf2bda4ed5d4945f5a71e7fa2c 100644 (file)
--- a/t/lei.t
+++ b/t/lei.t
@@ -187,7 +187,7 @@ my $test_external = sub {
        is($? >> 8, 1, 'errored out with exit 1');
 
        ok(!$lei->(qw(q s:prefix -f mboxcl2 -o), $home), 'bad mbox');
-       like($err, qr!\Q$home\E exists and is not a regular file!,
+       like($err, qr!\Q$home\E exists and is not a writable file!,
                'error shown');
        is($? >> 8, 1, 'errored out with exit 1');