| 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'
MC/DC0%0/1
$args->{'exe'} || 'mutt_dotlock'
$args->{'exe'}
Truth table0%0/2
A
A= $args->{'exe'}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | system $self->exe, '-u', $self->filename | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 73 | or return $self->SUPER::lock; # success | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | 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
| |||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | { system $exe, '-f', '-u', $filename | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 2 | 1; | |||||||||||||||||||||||||||