| 1 | package FFI::Temp; | |||||||||||||||||||||||||||||||
| 2 | ||||||||||||||||||||||||||||||||
| 3 | 18 | ▶ | use strict; | |||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||
| 4 | 18 | ▶ | use warnings; | |||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||
| 5 | 18 | ▶ | use 5.008004; | |||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||
| 6 | 18 | ▶ | use Carp qw( croak ); | |||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||
| 7 | 18 | ▶ | use File::Spec; | |||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||
| 8 | 18 | ▶ | use File::Temp qw( tempdir ); | |||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||
| 9 | ||||||||||||||||||||||||||||||||
| 10 | # ABSTRACT: Temp Dir support for FFI::Platypus | |||||||||||||||||||||||||||||||
| 11 | 18 | our $VERSION = '2.12'; # VERSION | ||||||||||||||||||||||||||||||
| 12 | ||||||||||||||||||||||||||||||||
| 13 | ||||||||||||||||||||||||||||||||
| 14 | # problem with vanilla File::Temp is that is often uses | |||||||||||||||||||||||||||||||
| 15 | # as /tmp that has noexec turned on. Workaround is to | |||||||||||||||||||||||||||||||
| 16 | # create a temp directory in the build directory, but | |||||||||||||||||||||||||||||||
| 17 | # we have to be careful about cleanup. This puts all that | |||||||||||||||||||||||||||||||
| 18 | # (attempted) carefulness in one place so that when we | |||||||||||||||||||||||||||||||
| 19 | # later discover it isn't so careful we can fix it in | |||||||||||||||||||||||||||||||
| 20 | # one place rather thabn alllll the places that we need | |||||||||||||||||||||||||||||||
| 21 | # temp directories. | |||||||||||||||||||||||||||||||
| 22 | ||||||||||||||||||||||||||||||||
| 23 | 18 | my %root; | ||||||||||||||||||||||||||||||
| 24 | ||||||||||||||||||||||||||||||||
| 25 | sub _root | |||||||||||||||||||||||||||||||
| 26 | 46 | ▶ | { | |||||||||||||||||||||||||||||
|
Subroutine
_root: called CC=7 SCAR=20.2
| ||||||||||||||||||||||||||||||||
| 27 | 46 | my $root = File::Spec->rel2abs(File::Spec->catdir(".tmp")); | ||||||||||||||||||||||||||||||
| 28 | 46 | my $lock = File::Spec->catfile($root, "l$$"); | ||||||||||||||||||||||||||||||
| 29 | ||||||||||||||||||||||||||||||||
| 30 | 46 | foreach my $try (0..9) | ||||||||||||||||||||||||||||||
| 31 | { | |||||||||||||||||||||||||||||||
| 32 | 46 | ▶ | sleep $try if $try != 0; | |||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||
| 33 | 46 | ▶ | mkdir $root or die "unable to create temp root $!" unless -d $root; | |||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
-d $root || (mkdir($root) || die("unable to create temp root $!"))
mkdir $root or die "unable to create temp root $!"
MC/DC0%0/2
-d $root || (mkdir($root) || die("unable to create temp root $!"))
-d $root
mkdir $root
Truth table66%2/3
A || B
A= -d $rootB= mkdir $root
| ||||||||||||||||||||||||||||||||
| 34 | ||||||||||||||||||||||||||||||||
| 35 | # There is a race condition here if the FFI::Temp is | |||||||||||||||||||||||||||||||
| 36 | # used in parallel. To work around we run this 10 | |||||||||||||||||||||||||||||||
| 37 | # times until it works. There is still a race condition | |||||||||||||||||||||||||||||||
| 38 | # if it fails 10 times, but hopefully that is unlikely. | |||||||||||||||||||||||||||||||
| 39 | ||||||||||||||||||||||||||||||||
| 40 | # ??: doesn't account for fork, but probably doesn't need to. | |||||||||||||||||||||||||||||||
| 41 | 46 | ▶ | open my $fh, '>', $lock or next; | |||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||
| 42 | 46 | ▶ | close $fh or next; | |||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||
| 43 | ||||||||||||||||||||||||||||||||
| 44 | 46 | $root{$root} = 1; | ||||||||||||||||||||||||||||||
| 45 | 46 | return $root; | ||||||||||||||||||||||||||||||
| 46 | } | |||||||||||||||||||||||||||||||
| 47 | } | |||||||||||||||||||||||||||||||
| 48 | ||||||||||||||||||||||||||||||||
| 49 | 18 | ▶ | END { | |||||||||||||||||||||||||||||
|
Subroutine
END: called CC=3 SCAR=11.1
| ||||||||||||||||||||||||||||||||
| 50 | 18 | foreach my $root (keys %root) | ||||||||||||||||||||||||||||||
| 51 | { | |||||||||||||||||||||||||||||||
| 52 | 13 | my $lock = File::Spec->catfile($root, "l$$"); | ||||||||||||||||||||||||||||||
| 53 | 13 | unlink $lock; | ||||||||||||||||||||||||||||||
| 54 | # try to delete if possible. | |||||||||||||||||||||||||||||||
| 55 | # if not possible then punt | |||||||||||||||||||||||||||||||
| 56 | 13 | ▶ | rmdir $root if -d $root; | |||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||
| 57 | } | |||||||||||||||||||||||||||||||
| 58 | } | |||||||||||||||||||||||||||||||
| 59 | ||||||||||||||||||||||||||||||||
| 60 | sub newdir | |||||||||||||||||||||||||||||||
| 61 | 26 | ▶ | { | |||||||||||||||||||||||||||||
|
Subroutine
newdir: called CC=2 SCAR=7.1
Pod
undocumented
| ||||||||||||||||||||||||||||||||
| 62 | 26 | my $class = shift; | ||||||||||||||||||||||||||||||
| 63 | 26 | ▶ | croak "uneven" if @_ % 2; | |||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||
| 64 | 26 | File::Temp->newdir(DIR => _root, @_); | ||||||||||||||||||||||||||||||
| 65 | } | |||||||||||||||||||||||||||||||
| 66 | ||||||||||||||||||||||||||||||||
| 67 | sub new | |||||||||||||||||||||||||||||||
| 68 | 20 | ▶ | { | |||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| ||||||||||||||||||||||||||||||||
| 69 | 20 | my $class = shift; | ||||||||||||||||||||||||||||||
| 70 | 20 | ▶ | croak "uneven" if @_ % 2; | |||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||
| 71 | 20 | File::Temp->new(DIR => _root, @_); | ||||||||||||||||||||||||||||||
| 72 | } | |||||||||||||||||||||||||||||||
| 73 | ||||||||||||||||||||||||||||||||
| 74 | 18 | 1; | ||||||||||||||||||||||||||||||
| 75 | ||||||||||||||||||||||||||||||||
| 76 | __END__ | |||||||||||||||||||||||||||||||