about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-01-20 14:04:43 +0900
committerEric Wong <e@80x24.org>2021-01-21 03:29:16 +0000
commit3dde6fa1268e2f86f10f26b7d427598e582aed2a (patch)
tree91594295d071ff279bcc4d18bc3fb3dc1e9d3334 /lib
parentb0b13249a538fc6f9a4c109d15d51170e3dd8bdd (diff)
downloadpublic-inbox-3dde6fa1268e2f86f10f26b7d427598e582aed2a.tar.gz
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
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/LeiOverview.pm6
-rw-r--r--lib/PublicInbox/LeiToMail.pm4
2 files changed, 4 insertions, 6 deletions
diff --git a/lib/PublicInbox/LeiOverview.pm b/lib/PublicInbox/LeiOverview.pm
index dcc3088b..cab2b055 100644
--- a/lib/PublicInbox/LeiOverview.pm
+++ b/lib/PublicInbox/LeiOverview.pm
@@ -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");
         }
diff --git a/lib/PublicInbox/LeiToMail.pm b/lib/PublicInbox/LeiToMail.pm
index 49b5c8ab..9d9b5748 100644
--- a/lib/PublicInbox/LeiToMail.pm
+++ b/lib/PublicInbox/LeiToMail.pm
@@ -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 {