]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei_mirror: reduce scope of v2 lock
authorEric Wong <e@80x24.org>
Mon, 28 Nov 2022 05:31:23 +0000 (05:31 +0000)
committerEric Wong <e@80x24.org>
Mon, 28 Nov 2022 23:38:54 +0000 (23:38 +0000)
Guarding against parallel clones isn't realistic, really, only
setting up all.git, and even then, I'm not 100% sure the lock
is useful.

lib/PublicInbox/LeiMirror.pm

index 9c457fcab054c6a68bdceaea5dce3c803dd05d8b..0a93ed440c868e73d375bd65cbc09c958bec2367 100644 (file)
@@ -377,9 +377,11 @@ sub v1_done { # called via OnDestroy
 sub v2_done { # called via OnDestroy
        my ($self) = @_;
        return if $self->{dry_run} || !$LIVE;
+       my $dst = $self->{cur_dst} // $self->{dst};
+       my $lk = bless { lock_path => "$dst/inbox.lock" }, 'PublicInbox::Lock';
+       my $lck = $lk->lock_for_scope($$);
        _write_inbox_config($self);
        require PublicInbox::MultiGit;
-       my $dst = $self->{cur_dst} // $self->{dst};
        my $mg = PublicInbox::MultiGit->new($dst, 'all.git', 'git');
        $mg->fill_alternates;
        for my $i ($mg->git_epochs) { $mg->epoch_cfg_set($i) }
@@ -393,7 +395,7 @@ sub v2_done { # called via OnDestroy
                chmod($st[2] & 0555, $edst) or die "chmod(a-w, $edst): $!";
        }
        write_makefile($dst, 2);
-       delete $self->{-locked} // die "BUG: $dst not locked"; # unlock
+       undef $lck; # unlock
        index_cloned_inbox($self, 2);
 }
 
@@ -443,7 +445,6 @@ failed to extract epoch number from $src
        (!$self->{dry_run} && !-d $dst) and File::Path::mkpath($dst);
 
        require PublicInbox::Lock;
-       my $lk = bless { lock_path => "$dst/inbox.lock" }, 'PublicInbox::Lock';
        my $fini = PublicInbox::OnDestroy->new($$, \&v2_done, $task);
 
        $lei->{opt}->{'inbox-config'} =~ /\A(?:always|v2)\z/s and
@@ -451,7 +452,6 @@ failed to extract epoch number from $src
 
        _get_txt_start($task, 'description', $fini);
 
-       $task->{-locked} = $lk->lock_for_scope($$) if !$self->{dry_run};
        my @cmd = clone_cmd($lei, my $opt = {});
        while (@src_edst && !$lei->{child_error}) {
                my $cmd = [ @$pfx, @cmd, splice(@src_edst, 0, 2) ];