| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Pcore::Util::File::TempDir; |
|
2
|
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
43
|
use Pcore -class, -const; |
|
|
5
|
|
|
|
|
11
|
|
|
|
5
|
|
|
|
|
39
|
|
|
4
|
5
|
|
|
5
|
|
48
|
use Pcore::Util::Scalar qw[refaddr]; |
|
|
5
|
|
|
|
|
13
|
|
|
|
5
|
|
|
|
|
40
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has base => ( is => 'lazy', isa => Str ); |
|
7
|
|
|
|
|
|
|
has tmpl => ( is => 'lazy', isa => Str ); |
|
8
|
|
|
|
|
|
|
has mode => ( is => 'lazy', isa => Maybe [ Int | Str ], default => 'rwx------' ); |
|
9
|
|
|
|
|
|
|
has umask => ( is => 'ro', isa => Maybe [ Int | Str ] ); |
|
10
|
|
|
|
|
|
|
has lazy => ( is => 'ro', isa => Bool, default => 0 ); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has path => ( is => 'lazy', isa => Str, init_arg => undef ); |
|
13
|
|
|
|
|
|
|
has owner_pid => ( is => 'ro', isa => Str, default => $$, init_arg => undef ); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use overload # |
|
16
|
|
|
|
|
|
|
q[""] => sub { |
|
17
|
0
|
|
|
0
|
|
0
|
return $_[0]->path; |
|
18
|
|
|
|
|
|
|
}, |
|
19
|
|
|
|
|
|
|
q[cmp] => sub { |
|
20
|
0
|
0
|
|
0
|
|
0
|
return !$_[2] ? $_[0]->path cmp $_[1] : $_[1] cmp $_[0]->path; |
|
21
|
|
|
|
|
|
|
}, |
|
22
|
|
|
|
|
|
|
q[0+] => sub { |
|
23
|
0
|
|
|
0
|
|
0
|
return refaddr $_[0]; |
|
24
|
|
|
|
|
|
|
}, |
|
25
|
5
|
|
|
5
|
|
36
|
fallback => undef; |
|
|
5
|
|
|
|
|
12
|
|
|
|
5
|
|
|
|
|
67
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
const our $TMPL => [ 0 .. 9, 'a' .. 'z', 'A' .. 'Z' ]; |
|
28
|
|
|
|
|
|
|
|
|
29
|
0
|
|
|
0
|
0
|
0
|
sub DEMOLISH ( $self, $global ) { |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# do not unlink files, created by others processes |
|
32
|
0
|
0
|
|
|
|
0
|
return if $self->owner_pid ne $$; |
|
33
|
|
|
|
|
|
|
|
|
34
|
0
|
|
|
0
|
|
0
|
local $SIG{__WARN__} = sub { }; |
|
35
|
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
0
|
P->file->rmtree( $self->path, safe => 0 ); |
|
37
|
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
0
|
return; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
5
|
|
|
5
|
0
|
22947
|
sub BUILD ( $self, $args ) { |
|
|
5
|
|
|
|
|
15
|
|
|
|
5
|
|
|
|
|
13
|
|
|
|
5
|
|
|
|
|
13
|
|
|
42
|
5
|
50
|
|
|
|
50
|
$self->path if !$self->lazy; |
|
43
|
|
|
|
|
|
|
|
|
44
|
5
|
|
|
|
|
50
|
return; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
0
|
|
|
0
|
|
|
sub _build_base ($self) { |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
return "$ENV->{TEMP_DIR}"; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
|
|
0
|
|
|
sub _build_tmpl ($self) { |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
return 'temp-' . $$ . '-XXXXXXXX'; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
|
|
0
|
|
|
sub _build_path ($self) { |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my $attempt = 3; |
|
57
|
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
REDO: |
|
59
|
|
|
|
|
|
|
die q[Can't create temporary directory] if !$attempt--; |
|
60
|
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $dirname = $self->tmpl =~ s/X/$TMPL->[rand $TMPL->@*]/smger; |
|
|
0
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
goto REDO if -e $self->base . q[/] . $dirname; |
|
64
|
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my $umask_guard; |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
$umask_guard = P->file->umask( $self->umask ) if defined $self->umask; |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
P->file->mkpath( $self->base . q[/] . $dirname, mode => $self->mode ); |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
return P->path( $self->base . q[/] . $dirname, is_dir => 1 )->realpath->to_string; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
|
75
|
|
|
|
|
|
|
__END__ |
|
76
|
|
|
|
|
|
|
=pod |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=encoding utf8 |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 NAME |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Pcore::Util::File::TempDir |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |