]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
pop3d: split @FLOCK into $FLOCK_TMPL and @FLOCK_ORDER
authorEric Wong <e@80x24.org>
Mon, 18 Sep 2023 10:15:14 +0000 (10:15 +0000)
committerEric Wong <e@80x24.org>
Wed, 20 Sep 2023 19:14:24 +0000 (19:14 +0000)
This improves readability since we don't have to subscript
the array for use with the `pack' perlop.

lib/PublicInbox/POP3D.pm

index 580a26d322cebfad2790625d00c09df3f40b500d..bee668fccc0806051bd9264dab987174c541227c 100644 (file)
@@ -13,7 +13,7 @@ use PublicInbox::POP3;
 use PublicInbox::Syscall;
 use File::Temp 0.19 (); # 0.19 for ->newdir
 use Fcntl qw(F_SETLK F_UNLCK F_WRLCK SEEK_SET);
-my @FLOCK;
+my ($FLOCK_TMPL, @FLOCK_ORDER);
 # are all BSDs the same "struct flock"? tested Free+Net+Open...
 if ($^O eq 'linux' || $^O =~ /bsd/) {
        require Config;
@@ -26,15 +26,15 @@ if ($^O eq 'linux' || $^O =~ /bsd/) {
 
        if (defined($off_t)) {
                if ($^O eq 'linux') {
-                       @FLOCK = ("ss\@8$off_t$off_t\@32",
-                               qw(l_type l_whence l_start l_len));
+                       $FLOCK_TMPL = "ss\@8$off_t$off_t\@32";
+                       @FLOCK_ORDER = qw(l_type l_whence l_start l_len);
                } elsif ($^O =~ /bsd/) { # @32 may be enough
-                       @FLOCK = ("${off_t}${off_t}lss\@256",
-                               qw(l_start l_len l_pid l_type l_whence));
+                       $FLOCK_TMPL = "${off_t}${off_t}lss\@256";
+                       @FLOCK_ORDER = qw(l_start l_len l_pid l_type l_whence);
                }
        }
 }
-@FLOCK or eval { require File::FcntlLock } or
+@FLOCK_ORDER or eval { require File::FcntlLock } or
        die "File::FcntlLock required for POP3 on $^O: $@\n";
 
 sub new {
@@ -141,9 +141,9 @@ sub _setlk ($%) {
        my ($self, %lk) = @_;
        $lk{l_pid} = 0; # needed for *BSD
        $lk{l_whence} = SEEK_SET;
-       if (@FLOCK) {
+       if (@FLOCK_ORDER) {
                fcntl($self->{txn_fh}, F_SETLK,
-                       pack($FLOCK[0], @lk{@FLOCK[1..$#FLOCK]}));
+                       pack($FLOCK_TMPL, @lk{@FLOCK_ORDER}));
        } else {
                my $fs = File::FcntlLock->new(%lk);
                $fs->lock($self->{txn_fh}, F_SETLK);