about summary refs log tree commit homepage
path: root/lib/PublicInbox/Import.pm
diff options
context:
space:
mode:
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-19 08:14:51 +0000
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-19 08:16:34 +0000
commit41bdfa63fa4c1a288e85720614436580fd0a9741 (patch)
treefae66bfbf0049c2abeac5ed1072171ca2bc41d25 /lib/PublicInbox/Import.pm
parent84e2b6ab9805b93174c5387740bea592064c80ea (diff)
downloadpublic-inbox-41bdfa63fa4c1a288e85720614436580fd0a9741.tar.gz
This reduces code duplication needed for locking and
and hopefully makes things easier to understand.
Diffstat (limited to 'lib/PublicInbox/Import.pm')
-rw-r--r--lib/PublicInbox/Import.pm17
1 files changed, 4 insertions, 13 deletions
diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm
index ca30ac44..fc740fa4 100644
--- a/lib/PublicInbox/Import.pm
+++ b/lib/PublicInbox/Import.pm
@@ -7,7 +7,7 @@
 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;
@@ -44,19 +44,13 @@ sub gfi_start {
         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};
 
-        if (my $lock_path = $self->{lock_path}) {
-                sysopen(my $lockfh, $lock_path, O_WRONLY|O_CREAT) or
-                        die "failed to open lock $lock_path: $!";
-                # wait for other processes to be done
-                flock($lockfh, LOCK_EX) or die "lock failed: $!\n";
-                $self->{lockfh} = $lockfh;
-        }
+        $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) };
@@ -384,10 +378,7 @@ sub done {
 
         _update_git_info($self, 1) if delete $self->{nchg};
 
-        $self->{lock_path} 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 {