package PublicInbox::Import;
use strict;
use warnings;
-use Fcntl qw(:flock :DEFAULT);
+use base qw(PublicInbox::Lock);
use PublicInbox::Spawn qw(spawn);
use PublicInbox::MID qw(mids mid_mime mid2path);
use PublicInbox::Address;
use PublicInbox::MsgTime qw(msg_timestamp);
use PublicInbox::ContentId qw(content_digest);
+use PublicInbox::MDA;
sub new {
my ($class, $git, $name, $email, $ibx) = @_;
ref => $ref,
inbox => $ibx,
path_type => '2/38', # or 'v2'
- ssoma_lock => 1, # disable for v2
+ lock_path => "$git->{git_dir}/ssoma.lock", # v2 changes this
bytes_added => 0,
}, $class
}
pipe($in_r, $in_w) or die "pipe failed: $!";
pipe($out_r, $out_w) or die "pipe failed: $!";
my $git = $self->{git};
- my $git_dir = $git->{git_dir};
- my $lockfh;
- if ($self->{ssoma_lock}) {
- my $lockpath = "$git_dir/ssoma.lock";
- sysopen($lockfh, $lockpath, O_WRONLY|O_CREAT) or
- die "failed to open lock $lockpath: $!";
- # wait for other processes to be done
- flock($lockfh, LOCK_EX) or die "lock failed: $!\n";
- }
+ $self->lock_acquire;
local $/ = "\n";
chomp($self->{tip} = $git->qx(qw(rev-parse --revs-only), $self->{ref}));
+ my $git_dir = $git->{git_dir};
my @cmd = ('git', "--git-dir=$git_dir", qw(fast-import
--quiet --done --date-format=raw));
my $rdr = { 0 => fileno($out_r), 1 => fileno($in_w) };
$out_w->autoflush(1);
$self->{in} = $in_r;
$self->{out} = $out_w;
- $self->{lockfh} = $lockfh;
$self->{pid} = $pid;
$self->{nchg} = 0;
binmode $out_w, ':raw' or die "binmode :raw failed: $!";
# kill potentially confusing/misleading headers
$mime->header_set($_) for qw(bytes lines content-length status);
+ $mime->header_set($_) for @PublicInbox::MDA::BAD_HEADERS;
# spam check:
if ($check_cb) {
_update_git_info($self, 1) if delete $self->{nchg};
- $self->{ssoma_lock} or return;
- my $lockfh = delete $self->{lockfh} or die "BUG: not locked: $!";
- flock($lockfh, LOCK_UN) or die "unlock failed: $!";
- close $lockfh or die "close lock failed: $!";
+ $self->lock_release;
}
sub atfork_child {
sub digest2mid ($) {
my ($dig) = @_;
- $dig->clone->hexdigest . '@localhost';
+ my $b64 = $dig->clone->b64digest;
+ # Make our own URLs nicer:
+ # See "Base 64 Encoding with URL and Filename Safe Alphabet" in RFC4648
+ $b64 =~ tr!+/=!-_!d;
+
+ # We can make this more meaningful with a date prefix or other things,
+ # but this is only needed for crap that fails to generate a Message-ID
+ # or reuses one. In other words, it's usually spammers who hit this
+ # so they don't deserve nice Message-IDs :P
+ $b64 . '@localhost';
}
1;