line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OPM::Installer::Utils::File; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: File related utility functions |
4
|
|
|
|
|
|
|
|
5
|
10
|
|
|
10
|
|
606189
|
use v5.10; |
|
10
|
|
|
|
|
93
|
|
6
|
|
|
|
|
|
|
|
7
|
10
|
|
|
10
|
|
48
|
use strict; |
|
10
|
|
|
|
|
14
|
|
|
10
|
|
|
|
|
174
|
|
8
|
10
|
|
|
10
|
|
40
|
use warnings; |
|
10
|
|
|
|
|
14
|
|
|
10
|
|
|
|
|
387
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.0.1'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
10
|
|
|
10
|
|
4293
|
use File::HomeDir; |
|
10
|
|
|
|
|
47500
|
|
|
10
|
|
|
|
|
485
|
|
13
|
10
|
|
|
10
|
|
66
|
use File::Spec; |
|
10
|
|
|
|
|
23
|
|
|
10
|
|
|
|
|
170
|
|
14
|
10
|
|
|
10
|
|
4755
|
use File::Temp; |
|
10
|
|
|
|
|
145102
|
|
|
10
|
|
|
|
|
665
|
|
15
|
10
|
|
|
10
|
|
5729
|
use HTTP::Tiny; |
|
10
|
|
|
|
|
273373
|
|
|
10
|
|
|
|
|
305
|
|
16
|
10
|
|
|
10
|
|
3603
|
use HTTP::Tiny::FileProtocol; |
|
10
|
|
|
|
|
208254
|
|
|
10
|
|
|
|
|
279
|
|
17
|
10
|
|
|
10
|
|
3371
|
use IO::All; |
|
10
|
|
|
|
|
71593
|
|
|
10
|
|
|
|
|
68
|
|
18
|
10
|
|
|
10
|
|
3821
|
use Moo; |
|
10
|
|
|
|
|
65576
|
|
|
10
|
|
|
|
|
52
|
|
19
|
10
|
|
|
10
|
|
13520
|
use OPM::Installer::Logger; |
|
10
|
|
|
|
|
26
|
|
|
10
|
|
|
|
|
292
|
|
20
|
10
|
|
|
10
|
|
3700
|
use OPM::Installer::Utils::Config; |
|
10
|
|
|
|
|
25
|
|
|
10
|
|
|
|
|
250
|
|
21
|
10
|
|
|
10
|
|
3386
|
use OPM::Repository; |
|
10
|
|
|
|
|
587166
|
|
|
10
|
|
|
|
|
344
|
|
22
|
10
|
|
|
10
|
|
70
|
use Regexp::Common qw(URI); |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
41
|
|
23
|
10
|
|
|
10
|
|
4533
|
use Types::Standard qw(ArrayRef Str Bool); |
|
10
|
|
|
|
|
465470
|
|
|
10
|
|
|
|
|
102
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our $ALLOWED_SCHEME = [ 'HTTP', 'file' ]; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has repositories => ( is => 'ro', isa => ArrayRef[Str], default => \&_repository_list ); |
28
|
|
|
|
|
|
|
has package => ( is => 'ro', isa => Str, required => 1 ); |
29
|
|
|
|
|
|
|
has framework_version => ( is => 'ro', isa => Str, required => 1 ); |
30
|
|
|
|
|
|
|
has version => ( is => 'ro', isa => Str ); |
31
|
|
|
|
|
|
|
has verbose => ( is => 'ro', isa => Bool ); |
32
|
|
|
|
|
|
|
has logger => ( is => 'ro', default => sub{ OPM::Installer::Logger->new } ); |
33
|
|
|
|
|
|
|
has rc_config => ( is => 'ro', lazy => 1, default => \&_rc_config ); |
34
|
|
|
|
|
|
|
has conf => ( is => 'ro' ); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub list_available { |
37
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
0
|
my @repositories = @{ $self->repositories || [] }; |
|
0
|
|
|
|
|
0
|
|
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
0
|
for my $repo_url ( @repositories ) { |
42
|
0
|
0
|
|
|
|
0
|
$repo_url .= '/otrs.xml' if '.xml' ne substr $repo_url, -4; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
0
|
my $repo = OPM::Repository->new( |
46
|
|
|
|
|
|
|
sources => \@repositories, |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
0
|
my $framework_version = $self->framework_version; |
50
|
0
|
|
|
|
|
0
|
$framework_version =~ s{\.\d+$}{}; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
0
|
return $repo->list( |
53
|
|
|
|
|
|
|
framework => $framework_version, |
54
|
|
|
|
|
|
|
details => 1, |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub resolve_path { |
59
|
12
|
|
|
12
|
1
|
50999
|
my ($self) = @_; |
60
|
|
|
|
|
|
|
|
61
|
12
|
|
|
|
|
26
|
my $path; |
62
|
|
|
|
|
|
|
|
63
|
12
|
|
|
|
|
52
|
my $package = $self->package; |
64
|
12
|
100
|
|
|
|
51
|
if ( $self->_is_url( $package ) ) { |
|
|
100
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# download file |
66
|
2
|
|
|
|
|
11
|
$path = $self->_download( $package ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
elsif ( -f $package ) { |
69
|
|
|
|
|
|
|
# do nothing, file already exists |
70
|
1
|
|
|
|
|
2
|
$path = $package; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
else { |
73
|
9
|
50
|
|
|
|
26
|
my @repositories = @{ $self->repositories || [] }; |
|
9
|
|
|
|
|
68
|
|
74
|
|
|
|
|
|
|
|
75
|
9
|
|
|
|
|
27
|
for my $repo ( @repositories ) { |
76
|
9
|
100
|
|
|
|
93
|
$repo .= '/otrs.xml' if '.xml' ne substr $repo, -4; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
9
|
50
|
|
|
|
45
|
say "Searching these repositories: @repositories" if $self->verbose; |
80
|
|
|
|
|
|
|
|
81
|
9
|
|
|
|
|
142
|
my $repo = OPM::Repository->new( |
82
|
|
|
|
|
|
|
sources => \@repositories, |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
|
85
|
9
|
|
|
|
|
29170
|
my ($framework) = $self->framework_version =~ m{\A(\d+\.\d+)}; |
86
|
|
|
|
|
|
|
|
87
|
9
|
|
|
|
|
72
|
my ($url) = $repo->find( |
88
|
|
|
|
|
|
|
name => $package, |
89
|
|
|
|
|
|
|
framework => $framework, |
90
|
|
|
|
|
|
|
version => $self->version, |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
|
93
|
9
|
50
|
0
|
|
|
24175
|
say "Found ", $url // '' if $self->verbose; |
94
|
|
|
|
|
|
|
|
95
|
9
|
100
|
|
|
|
63
|
return if !$url; |
96
|
|
|
|
|
|
|
|
97
|
6
|
|
|
|
|
28
|
$path = $self->_download( $url ); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
9
|
|
|
|
|
263
|
return $path; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub _repository_list { |
104
|
0
|
|
|
0
|
|
0
|
my ($self) = @_; |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
0
|
my $config = $self->rc_config; |
107
|
0
|
|
|
|
|
0
|
my $repositories = $config->{repository}; |
108
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
0
|
return [] if !$repositories; |
110
|
0
|
|
|
|
|
0
|
return $repositories; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub _is_url { |
114
|
19
|
|
|
19
|
|
3213
|
my ($self, $package) = @_; |
115
|
|
|
|
|
|
|
|
116
|
19
|
50
|
|
|
|
76
|
my @allowed_schemes = ref $ALLOWED_SCHEME ? @{ $ALLOWED_SCHEME } : $ALLOWED_SCHEME; |
|
19
|
|
|
|
|
59
|
|
117
|
|
|
|
|
|
|
|
118
|
19
|
|
|
|
|
34
|
my $matches; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
SCHEME: |
121
|
19
|
|
|
|
|
43
|
for my $scheme ( @allowed_schemes ) { |
122
|
|
|
|
|
|
|
my $regex = ( lc $scheme eq 'http' ) ? |
123
|
|
|
|
|
|
|
$RE{URI}{HTTP}{-scheme => qr/https?/} : |
124
|
34
|
100
|
|
|
|
4300
|
$RE{URI}{$scheme}; |
125
|
|
|
|
|
|
|
|
126
|
34
|
100
|
|
|
|
1767
|
if ( $package =~ m{\A$regex\z} ) { |
127
|
7
|
|
|
|
|
917
|
$matches++; |
128
|
7
|
|
|
|
|
35
|
last SCHEME; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
19
|
100
|
|
|
|
1951
|
return if !$matches; |
133
|
7
|
|
|
|
|
19
|
return 1; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub _download { |
137
|
8
|
|
|
8
|
|
27
|
my ($self, $url) = @_; |
138
|
|
|
|
|
|
|
|
139
|
8
|
|
|
|
|
85
|
my $file = File::Temp->new->filename; |
140
|
8
|
|
|
|
|
3885
|
my $response = HTTP::Tiny->new->mirror( $url, $file ); |
141
|
|
|
|
|
|
|
|
142
|
8
|
|
|
|
|
13685
|
$self->logger->notice( area => 'download', file => $file, success => $response->{success} ); |
143
|
|
|
|
|
|
|
|
144
|
8
|
50
|
|
|
|
4794
|
return if !$response->{success}; |
145
|
8
|
|
|
|
|
1030
|
return $file; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub _rc_config { |
149
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
my $utils = OPM::Installer::Utils::Config->new( conf => $self->conf ); |
152
|
0
|
|
|
|
|
|
my $config = $utils->rc_config; |
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
return $config; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
1; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
__END__ |