unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 14/21] treewide: use PublicInbox::Lock->new
Date: Wed,  4 Oct 2023 03:49:26 +0000	[thread overview]
Message-ID: <20231004034933.3343930-15-e@80x24.org> (raw)
In-Reply-To: <20231004034933.3343930-1-e@80x24.org>

This gets rid of a few bare bless statements and helps
ensure we properly load Lock.pm before using it.
---
 lib/PublicInbox/LEI.pm        | 2 +-
 lib/PublicInbox/LeiMirror.pm  | 2 +-
 lib/PublicInbox/TestCommon.pm | 7 +++----
 t/solver_git.t                | 3 ++-
 t/v2mirror.t                  | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index d611f5c3..a5a6d321 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -1311,7 +1311,7 @@ sub lazy_start {
 	my ($sock_dir) = ($path =~ m!\A(.+?)/[^/]+\z!);
 	$errors_log = "$sock_dir/errors.log";
 	my $addr = pack_sockaddr_un($path);
-	my $lk = bless { lock_path => $errors_log }, 'PublicInbox::Lock';
+	my $lk = PublicInbox::Lock->new($errors_log);
 	umask(077) // die("umask(077): $!");
 	$lk->lock_acquire;
 	socket($listener, AF_UNIX, SOCK_SEQPACKET, 0) or die "socket: $!";
diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm
index c99bafc3..9d8a8963 100644
--- a/lib/PublicInbox/LeiMirror.pm
+++ b/lib/PublicInbox/LeiMirror.pm
@@ -873,7 +873,7 @@ sub v2_done { # called via OnDestroy
 	return if $self->{dry_run} || !keep_going($self);
 	my $dst = $self->{cur_dst} // $self->{dst};
 	require PublicInbox::Lock;
-	my $lk = bless { lock_path => "$dst/inbox.lock" }, 'PublicInbox::Lock';
+	my $lk = PublicInbox::Lock->new("$dst/inbox.lock");
 	my $lck = $lk->lock_for_scope($$);
 	_write_inbox_config($self);
 	require PublicInbox::MultiGit;
diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index 7d0eb2c4..32213fde 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -742,8 +742,7 @@ sub setup_public_inboxes () {
 	return @ret if -f $stamp;
 
 	require PublicInbox::Lock;
-	my $lk = bless { lock_path => "$test_home/setup.lock" },
-			'PublicInbox::Lock';
+	my $lk = PublicInbox::Lock->new("$test_home/setup.lock");
 	my $end = $lk->lock_for_scope;
 	return @ret if -f $stamp;
 
@@ -798,7 +797,7 @@ sub create_coderepo ($$;@) {
 		my $err = $!;
 		-d $dir or xbail "mkdir($dir): $err";
 	}
-	my $lk = bless { lock_path => "$dir/creat.lock" }, 'PublicInbox::Lock';
+	my $lk = PublicInbox::Lock->new("$dir/creat.lock");
 	my $scope = $lk->lock_for_scope;
 	my $tmpdir = delete $opt{tmpdir};
 	if (!-f "$dir/creat.stamp") {
@@ -830,7 +829,7 @@ sub create_inbox ($$;@) {
 		my $err = $!;
 		-d $dir or xbail "mkdir($dir): $err";
 	}
-	my $lk = bless { lock_path => "$dir/creat.lock" }, 'PublicInbox::Lock';
+	my $lk = PublicInbox::Lock->new("$dir/creat.lock");
 	$opt{inboxdir} = File::Spec->rel2abs($dir);
 	$opt{name} //= $ident;
 	my $scope = $lk->lock_for_scope;
diff --git a/t/solver_git.t b/t/solver_git.t
index f8cafa5e..4f09e05b 100644
--- a/t/solver_git.t
+++ b/t/solver_git.t
@@ -223,7 +223,8 @@ SKIP: {
 	};
 	my %bin = (big => $big_size, small => 1);
 	my %oid; # (small|big) => OID
-	my $lk = bless { lock_path => $l }, 'PublicInbox::Lock';
+	require PublicInbox::Lock;
+	my $lk = PublicInbox::Lock->new($l);
 	my $acq = $lk->lock_for_scope;
 	my $stamp = "$binfoo/stamp-";
 	if (open my $fh, '<', $stamp) {
diff --git a/t/v2mirror.t b/t/v2mirror.t
index 88b67bc1..b8824182 100644
--- a/t/v2mirror.t
+++ b/t/v2mirror.t
@@ -335,7 +335,7 @@ SKIP: {
 	chomp $oldrev;
 	my ($base) = ($0 =~ m!\b([^/]+)\.[^\.]+\z!);
 	my $wt = "t/data-gen/$base.pre-manifest-$oldrev";
-	my $lk = bless { lock_path => __FILE__ }, 'PublicInbox::Lock';
+	my $lk = PublicInbox::Lock->new(__FILE__);
 	$lk->lock_acquire;
 	my $psgi = "$wt/app.psgi";
 	if (!-f $psgi) { # checkout a pre-manifest.js.gz version

  parent reply	other threads:[~2023-10-04  3:49 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-04  3:49 [PATCH 00/21] lei + IPC related stuff Eric Wong
2023-10-04  3:49 ` [PATCH 01/21] lei: drop stores explicitly at daemon shutdown Eric Wong
2023-10-04  3:49 ` [PATCH 02/21] ds: hoist out close_non_busy Eric Wong
2023-10-04  3:49 ` [PATCH 03/21] ds: don't pass FD map to post_loop_do callback Eric Wong
2023-10-04  3:49 ` [PATCH 04/21] move all non-test @post_loop_do into named subs Eric Wong
2023-10-04  3:49 ` [PATCH 05/21] lei: close DirIdle (inotify) early at daemon shutdown Eric Wong
2023-10-04  3:49 ` [PATCH 06/21] input_pipe: {args} is never undefined Eric Wong
2023-10-04  3:49 ` [PATCH 07/21] lei: do_env combines fchdir and local Eric Wong
2023-10-04  3:49 ` [PATCH 08/21] lei: get rid of l2m_progress PktOp callback Eric Wong
2023-10-04  3:49 ` [PATCH 09/21] t/lei_to_mail: modernize and document test Eric Wong
2023-10-04  3:49 ` [PATCH 10/21] lei: reuse PublicInbox::Config::noop Eric Wong
2023-10-04  3:49 ` [PATCH 11/21] lei: keep signals blocked on daemon shutdown Eric Wong
2023-10-04  3:49 ` [PATCH 12/21] mbox_lock: retry on EINTR and use autodie Eric Wong
2023-10-04  3:49 ` [PATCH 13/21] lock: retry on EINTR, improve error reporting Eric Wong
2023-10-04  3:49 ` Eric Wong [this message]
2023-10-04  3:49 ` [PATCH 15/21] gcf2: use PublicInbox::Lock Eric Wong
2023-10-04  3:49 ` [PATCH 16/21] spawn: use autodie and PublicInbox::Lock Eric Wong
2023-10-04  3:49 ` [PATCH 17/21] xap_helper: retry flock on EINTR Eric Wong
2023-10-04  3:49 ` [PATCH 18/21] xap_helper.pm: use EINTR-aware recv_cmd Eric Wong
2023-10-04  3:49 ` [PATCH 19/21] spawn: drop checks for directory writability Eric Wong
2023-10-04  3:49 ` [PATCH 20/21] lei: document and local-ize $OPT hashref Eric Wong
2023-10-04  3:49 ` [PATCH 21/21] searchidx: fix redundant `in' in warning message Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231004034933.3343930-15-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).