diff options
author | Eric Wong <e@80x24.org> | 2021-02-25 22:41:39 -1100 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-02-26 17:03:53 -0400 |
commit | d540245cfff927692bed39b8cbe7c621452bc4b2 (patch) | |
tree | 1d877d0024d547687195a0978fa29168d31fbf2a /lib/PublicInbox/LeiImport.pm | |
parent | 3104d7492aa4aee07455dcad7449f786188afdf5 (diff) | |
download | public-inbox-d540245cfff927692bed39b8cbe7c621452bc4b2.tar.gz |
In case somebody is writing non-atomically, ensure we take read locks when opening mbox files for reading. v2: squash: load MboxLock even for .eml files
Diffstat (limited to 'lib/PublicInbox/LeiImport.pm')
-rw-r--r-- | lib/PublicInbox/LeiImport.pm | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/PublicInbox/LeiImport.pm b/lib/PublicInbox/LeiImport.pm index 7f247b64..c2c98030 100644 --- a/lib/PublicInbox/LeiImport.pm +++ b/lib/PublicInbox/LeiImport.pm @@ -80,10 +80,11 @@ sub call { # the main "lei import" method my $ifmt = lc $1; if (($fmt // $ifmt) ne $ifmt) { return $lei->fail(<<""); ---format=$fmt and `$ifmt:' conflict +--in-format=$fmt and `$ifmt:' conflict } if (-f $input_path) { + require PublicInbox::MboxLock; require PublicInbox::MboxReader; PublicInbox::MboxReader->can($ifmt) or return $lei->fail("$ifmt not supported"); @@ -142,7 +143,7 @@ error reading $input: $! $cb->(undef, $fh, \&_import_eml, $lei->{sto}, $set_kw); } }; - $lei->child_error(1 << 8, "<stdin>: $@") if $@; + $lei->child_error(1 << 8, "$input: $@") if $@; } sub _import_maildir { # maildir_each_file cb @@ -171,10 +172,10 @@ sub import_path_url { $ifmt = lc $1; } if (-f $input) { - open my $fh, '<', $input or return $lei->child_error(1 << 8, <<""); -unable to open $input: $! - - _import_fh($lei, $fh, $input, $ifmt); + my $m = $lei->{opt}->{'lock'} // ($ifmt eq 'eml' ? ['none'] : + PublicInbox::MboxLock->defaults); + my $mbl = PublicInbox::MboxLock->acq($input, 0, $m); + _import_fh($lei, $mbl->{fh}, $input, $ifmt); } elsif (-d _ && (-d "$input/cur" || -d "$input/new")) { return $lei->fail(<<EOM) if $ifmt && $ifmt ne 'maildir'; $input appears to a be a maildir, not $ifmt |