| 1 | # Copyrights 2001-2020 by [Mark Overmeer]. | ||||||||||||||||||||||||||||
| 2 | # For other contributors see ChangeLog. | ||||||||||||||||||||||||||||
| 3 | # See the manual pages for details on the licensing terms. | ||||||||||||||||||||||||||||
| 4 | # Pod stripped from pm file by OODoc 2.02. | ||||||||||||||||||||||||||||
| 5 | # This code is part of distribution Mail-Box. Meta-POD processed with | ||||||||||||||||||||||||||||
| 6 | # OODoc into POD and HTML manual-pages. See README.md | ||||||||||||||||||||||||||||
| 7 | # Copyright Mark Overmeer. Licensed under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | package Mail::Box::Locker::Mutt; | ||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | $VERSION = '3.009'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use base 'Mail::Box::Locker'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use POSIX qw/sys_wait_h/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | sub init($) | ||||||||||||||||||||||||||||
| 22 | 0 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 23 | 0 | $self->SUPER::init($args); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | ▶ | $self->{MBLM_exe} = $args->{exe} || 'mutt_dotlock'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'exe'} || 'mutt_dotlock'
MC/DC0%0/1
$args->{'exe'} || 'mutt_dotlock'
$args->{'exe'}
Truth table0%0/2
A
A= $args->{'exe'}
| |||||||||||||||||||||||||||||
| 26 | 0 | $self; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub name() {'MUTT'} | ||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub lockfile() { shift->filename . '.lock' } | ||||||||||||||||||||||||||
|
Subroutine
lockfile: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub exe() {shift->{MBLM_exe}} | ||||||||||||||||||||||||||
|
Subroutine
exe: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | sub unlock() | ||||||||||||||||||||||||||||
| 39 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
unlock: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | $self->hasLock | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | or return $self; | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | unless(system($self->exe, '-u', $self->filename)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | { my $folder = $self->folder; | |||||||||||||||||||||||||||
| 45 | 0 | $self->log(WARNING => "Couldn't remove mutt-unlock $folder: $!"); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | $self->SUPER::unlock; | |||||||||||||||||||||||||||
| 49 | 0 | $self; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | sub lock() | ||||||||||||||||||||||||||||
| 55 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
lock: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | 0 | my $folder = $self->folder; | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | if($self->hasLock) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | { $self->log(WARNING => "Folder $folder already mutt-locked"); | |||||||||||||||||||||||||||
| 59 | 0 | return 1; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | my $filename = $self->filename; | |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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 | ▶ | if(system($exe, '-p', '-r', 1, $filename)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | { unless(WIFEXITED($?) && WEXITSTATUS($?)==3) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
WIFEXITED($?) and WEXITSTATUS($?) == 3
MC/DC0%0/2
WIFEXITED($?) and WEXITSTATUS($?) == 3
WIFEXITED($?)
WEXITSTATUS($?) == 3
Truth table0%0/3
A and B
A= WIFEXITED($?)B= WEXITSTATUS($?) == 3
| |||||||||||||||||||||||||||||
| 74 | 0 | { $self->log(ERROR => "Will never get a mutt-lock: $!"); | |||||||||||||||||||||||||||
| 75 | 0 | return 0; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | else | ||||||||||||||||||||||||||||
| 79 | 0 | { return $self->SUPER::lock; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if(-e $lockfn && -A $lockfn > $expire) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-e $lockfn and -A $lockfn > $expire
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
| |||||||||||||||||||||||||||||
| 83 | { | ||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if(system($exe, '-f', '-u', $filename)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 0 | { $self->log(ERROR => | |||||||||||||||||||||||||||
| 86 | "Failed to remove expired mutt-lock $lockfn: $!"); | ||||||||||||||||||||||||||||
| 87 | 0 | last; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | else | ||||||||||||||||||||||||||||
| 90 | 0 | { $self->log(WARNING => "Removed expired mutt-lock $lockfn"); | |||||||||||||||||||||||||||
| 91 | 0 | redo; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | last unless --$end; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | sleep 1; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | return 0; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | sub isLocked() | ||||||||||||||||||||||||||||
| 104 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
isLocked: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 105 | 0 | system($self->exe, '-t', $self->filename); | |||||||||||||||||||||||||||
| 106 | 0 | ▶ | WIFEXITED($?) && WEXITSTATUS($?)==3; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 2 | 1; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||