Box/Locker/Mutt.pm

filter: Statementstmt 36.7% 18 / 49 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 45.4% 5 / 11 Podpod 66.6% 4 / 6 totaltotal 27.2% 27 / 99 CC 14 SCAR 38.9
CC
14
Cov
23%
lock
110.0
unlock
12.0
init
6.0
CRAP 48.7
« Box/Maildir.pm ↑ Summary Box/Manage/User.pm »
1 # This code is part of Perl distribution Mail-Box version 4.02.
2 # The POD got stripped from this file by OODoc version 3.06.
3 # For contributors see file ChangeLog.
4  
5 # This software is copyright (c) 2001-2026 by Mark Overmeer.
6  
7 # This is free software; you can redistribute it and/or modify it under
8 # the same terms as the Perl 5 programming language system itself.
9 # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
10  
11  
12 package Mail::Box::Locker::Mutt;{
13 2 our $VERSION = '4.02';
14 }
15  
16 2 ▶use parent 'Mail::Box::Locker';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 2 ▶use Log::Report 'mail-box', import => [ qw/__x fault warning/ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 2 ▶use POSIX qw/sys_wait_h/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 #--------------------
26  
27 sub init($)
28 0 ▶{ my ($self, $args) = @_;
Subroutine init: not called CC=2 SCAR=17.9
Pod undocumented
29 0 $self->SUPER::init($args);
30  
31 0 ▶ $self->{MBLM_exe} = $args->{exe} || 'mutt_dotlock';
Condition0%0/2
$args->{'exe'} || 'mutt_dotlock'
l!l
00
MC/DC0%0/1
$args->{'exe'} || 'mutt_dotlock'
$args->{'exe'}
Truth table0%0/2
A
A= $args->{'exe'}
Aresult
11
00
32 0 $self;
33 }
34  
35 sub name() { 'MUTT' }
36 0 ▶sub lockfile() { $_[0]->filename . '.lock' }
Subroutine lockfile: not called CC=1 SCAR=6.9
Pod undocumented
37  
38 #--------------------
39  
40 0 ▶sub exe() { $_[0]->{MBLM_exe} }
Subroutine exe: not called CC=1 SCAR=6.9
Pod documented
41  
42 #--------------------
43  
44 sub unlock()
45 0 ▶{ my $self = shift;
Subroutine unlock: not called CC=3 SCAR=24.8
Pod documented
46 0 ▶ $self->hasLock or return $self;
Branch: 1 branch
BranchTrueFalseTotal
$self->hasLock or return $self 0 0 0
47  
48 0 ▶ system $self->exe, '-u', $self->filename
Branch: 1 branch
BranchTrueFalseTotal
system $self->exe, "-u", $self->filename and &warning(&__x("couldn't remove mutt-unlock {folder}", "folder", $self->folder)) 0 0 0
49 and warning __x"couldn't remove mutt-unlock {folder}", folder => $self->folder;
50  
51 0 $self->SUPER::unlock;
52 0 $self;
53 }
54  
55  
56 sub lock()
57 0 ▶{ my $self = shift;
Subroutine lock: not called CC=10 SCAR=47.0
Pod documented
58 0 my $filename = $self->filename;
59  
60 0 ▶ $self->hasLock
Branch: 1 branch
BranchTrueFalseTotal
$self->hasLock and &warning(&__x("folder {name} already mutt-locked with {file}.", "name", $self->folder, "file", $filename)), (return 1) 0 0 0
61 and warning(__x"folder {name} already mutt-locked with {file}.", name => $self->folder, file => $filename), return 1;
62  
63 0 my $lockfn = $self->lockfile;
64  
65 0 my $timeout = $self->timeout;
66 0 ▶ my $end = $timeout eq 'NOTIMEOUT' ? -1 : $timeout;
Branch: 1 branch
BranchTrueFalseTotal
$timeout eq 'NOTIMEOUT' ? : 0 0 0
67 0 my $expire = $self->expires / 86400; # in days for -A
68 0 my $exe = $self->exe;
69  
70 0 while(1)
71 {
72 0 ▶ system $exe, '-p', '-r', 1, $filename
Branch: 1 branch
BranchTrueFalseTotal
system $exe, "-p", "-r", 1, $filename or return $self->SUPER::lock 0 0 0
73 or return $self->SUPER::lock; # success
74  
75 0 ▶ WIFEXITED($?) && WEXITSTATUS($?)==3
Branch: 1 branch
BranchTrueFalseTotal
WIFEXITED($?) and WEXITSTATUS($?) == 3 or &fault(&__x("folder {name} will never get a mutt-lock with {file}", "name", $self->folder, "file", $filename)) 0 0 0
Condition0%0/3
WIFEXITED($?) and WEXITSTATUS($?) == 3
!ll&&!rl&&r
000
MC/DC0%0/2
WIFEXITED($?) and WEXITSTATUS($?) == 3
WIFEXITED($?) WEXITSTATUS($?) == 3
Truth table0%0/3
A and B
A= WIFEXITED($?)B= WEXITSTATUS($?) == 3
ABresult
0X0
100
111
76 or fault __x"folder {name} will never get a mutt-lock with {file}", name => $self->folder, file => $filename;
77  
78 0 ▶ if(-e $lockfn && -A $lockfn > $expire)
Branch: 1 branch
BranchTrueFalseTotal
if (-e $lockfn and -A $lockfn > $expire) 0 0 0
Condition0%0/3
-e $lockfn and -A $lockfn > $expire
!ll&&!rl&&r
000
MC/DC0%0/2
-e $lockfn and -A $lockfn > $expire
-e $lockfn -A $lockfn > $expire
Truth table0%0/3
A and B
A= -e $lockfnB= -A $lockfn > $expire
ABresult
0X0
100
111
79 0 ▶ { system $exe, '-f', '-u', $filename
Branch: 1 branch
BranchTrueFalseTotal
system $exe, "-f", "-u", $filename and &warning(&__x("removed expired mutt-lock file {file}.", "file", $lockfn)), redo 0 0 0
80 and warning(__x"removed expired mutt-lock file {file}.", file => $lockfn), redo;
81  
82 0 fault __x"failed to remove expired mutt-lock {file}", file => $lockfn;
83 }
84  
85 0 ▶ --$end or last;
Branch: 1 branch
BranchTrueFalseTotal
--$end or last 0 0 0
86 0 sleep 1;
87 }
88  
89 0 0;
90 }
91  
92 sub isLocked()
93 0 ▶{ my $self = shift;
Subroutine isLocked: not called CC=2 SCAR=17.9
Pod documented
94 0 system $self->exe, '-t', $self->filename;
95 0 ▶ WIFEXITED($?) && WEXITSTATUS($?)==3;
Branch: 1 branch
BranchTrueFalseTotal
WIFEXITED($?) and WEXITSTATUS($?) == 3 0 0 0
96 }
97  
98 2 1;
« Box/Maildir.pm ↑ Summary Box/Manage/User.pm »