line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OPM::Maker::Command::filetest; |
2
|
|
|
|
|
|
|
$OPM::Maker::Command::filetest::VERSION = '1.15'; |
3
|
|
|
|
|
|
|
# ABSTRACT: check if filelist in .sopm includes the files on your disk |
4
|
|
|
|
|
|
|
|
5
|
22
|
|
|
22
|
|
15780
|
use strict; |
|
22
|
|
|
|
|
51
|
|
|
22
|
|
|
|
|
665
|
|
6
|
22
|
|
|
22
|
|
111
|
use warnings; |
|
22
|
|
|
|
|
38
|
|
|
22
|
|
|
|
|
607
|
|
7
|
|
|
|
|
|
|
|
8
|
22
|
|
|
22
|
|
111
|
use Carp qw(croak); |
|
22
|
|
|
|
|
61
|
|
|
22
|
|
|
|
|
1075
|
|
9
|
22
|
|
|
22
|
|
4773
|
use File::Find::Rule; |
|
22
|
|
|
|
|
76711
|
|
|
22
|
|
|
|
|
269
|
|
10
|
22
|
|
|
22
|
|
5338
|
use Path::Class (); |
|
22
|
|
|
|
|
261249
|
|
|
22
|
|
|
|
|
606
|
|
11
|
22
|
|
|
22
|
|
10122
|
use Text::Gitignore qw(match_gitignore); |
|
22
|
|
|
|
|
21173
|
|
|
22
|
|
|
|
|
1409
|
|
12
|
22
|
|
|
22
|
|
6177
|
use XML::LibXML; |
|
22
|
|
|
|
|
390599
|
|
|
22
|
|
|
|
|
165
|
|
13
|
|
|
|
|
|
|
|
14
|
22
|
|
|
22
|
|
6558
|
use OPM::Maker -command; |
|
22
|
|
|
|
|
59
|
|
|
22
|
|
|
|
|
176
|
|
15
|
22
|
|
|
|
|
14878
|
use OPM::Maker::Utils qw( |
16
|
|
|
|
|
|
|
reformat_size |
17
|
|
|
|
|
|
|
check_args_sopm |
18
|
22
|
|
|
22
|
|
93427
|
); |
|
22
|
|
|
|
|
55
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub abstract { |
21
|
1
|
|
|
1
|
1
|
3369
|
return "Check if filelist in .sopm includes the files on your disk"; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub usage_desc { |
25
|
1
|
|
|
1
|
1
|
962
|
return "opmbuild filetest "; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub validate_args { |
29
|
16
|
|
|
16
|
1
|
17345
|
my ($self, $opt, $args) = @_; |
30
|
|
|
|
|
|
|
|
31
|
16
|
|
|
|
|
57
|
my $sopm = check_args_sopm( $args ); |
32
|
|
|
|
|
|
|
|
33
|
16
|
100
|
|
|
|
89
|
$self->usage_error( 'need path to .sopm' ) if |
34
|
|
|
|
|
|
|
!$sopm; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub execute { |
38
|
12
|
|
|
12
|
1
|
12311
|
my ($self, $opt, $args) = @_; |
39
|
|
|
|
|
|
|
|
40
|
12
|
|
|
|
|
46
|
my $file = check_args_sopm( $args ); |
41
|
|
|
|
|
|
|
|
42
|
11
|
|
|
|
|
25
|
my %opts; |
43
|
11
|
50
|
|
|
|
46
|
if ( !$ENV{OPM_UNSECURE} ) { |
44
|
11
|
|
|
|
|
43
|
%opts = ( |
45
|
|
|
|
|
|
|
no_network => 1, |
46
|
|
|
|
|
|
|
expand_entities => 0, |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
11
|
|
|
|
|
139
|
my $size = -s $file; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# if file is big, but not "too big" |
53
|
11
|
|
|
|
|
31
|
my $max_size = 31_457_280; |
54
|
11
|
100
|
|
|
|
1218
|
if ( $ENV{OPM_MAX_SIZE} ) { |
55
|
7
|
|
|
|
|
22
|
$max_size = reformat_size( $ENV{OPM_MAX_SIZE} ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
11
|
100
|
|
|
|
36
|
if ( $size > $max_size ) { |
59
|
1
|
|
|
|
|
212
|
croak "$file too big (max size: $max_size bytes)"; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
10
|
50
|
|
|
|
28
|
if ( $size > 10_000_000 ) { |
63
|
0
|
|
|
|
|
0
|
$opts{huge} = 1; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
10
|
|
|
|
|
1019
|
my $parser = XML::LibXML->new( %opts ); |
67
|
10
|
|
|
|
|
997
|
my $tree = $parser->parse_file( $file ); |
68
|
|
|
|
|
|
|
|
69
|
10
|
|
|
|
|
3671
|
my $sopm_path = Path::Class::File->new( $file ); |
70
|
10
|
|
|
|
|
1425
|
my $path = $sopm_path->dir; |
71
|
|
|
|
|
|
|
|
72
|
10
|
|
|
|
|
172
|
my $path_str = $path->stringify; |
73
|
10
|
|
|
|
|
474
|
my $hidden_files = File::Find::Rule->file->name(".*"); |
74
|
10
|
|
|
|
|
1550
|
my @files_in_fs = File::Find::Rule->file |
75
|
|
|
|
|
|
|
->not( $hidden_files ) |
76
|
|
|
|
|
|
|
->in ( $path_str ); |
77
|
|
|
|
|
|
|
|
78
|
31
|
|
|
|
|
198
|
my %fs = map{ $_ =~ s{\A\Q$path_str\E/?}{}; $_ => 1 } |
|
31
|
|
|
|
|
112
|
|
79
|
10
|
|
|
|
|
14525
|
grep{ $_ !~ /\.git|CVS|svn/ }@files_in_fs; |
|
31
|
|
|
|
|
135
|
|
80
|
|
|
|
|
|
|
|
81
|
10
|
|
|
|
|
51
|
delete $fs{ $sopm_path->basename }; |
82
|
|
|
|
|
|
|
|
83
|
10
|
|
|
|
|
77
|
my $ignore_file = Path::Class::File->new( |
84
|
|
|
|
|
|
|
$path->stringify, |
85
|
|
|
|
|
|
|
'.opmbuild_filetest_ignore', |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
|
88
|
10
|
|
|
|
|
1182
|
my $root_elem = $tree->getDocumentElement; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# retrieve file information |
91
|
10
|
|
|
|
|
78
|
my @files = $root_elem->findnodes( 'Filelist/File' ); |
92
|
|
|
|
|
|
|
|
93
|
10
|
|
|
|
|
732
|
my @not_found; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
FILE: |
96
|
10
|
|
|
|
|
28
|
for my $file ( @files ) { |
97
|
19
|
|
|
|
|
73
|
my $name = $file->findvalue( '@Location' ); |
98
|
|
|
|
|
|
|
|
99
|
19
|
100
|
|
|
|
2173
|
push @not_found, $name if !delete $fs{$name}; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
10
|
100
|
|
|
|
37
|
if ( @not_found ) { |
103
|
|
|
|
|
|
|
print "Files listed in .sopm but not found on disk:\n", |
104
|
1
|
|
|
|
|
3
|
map{ " - $_\n" }@not_found; |
|
2
|
|
|
|
|
55
|
|
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
10
|
|
|
|
|
20
|
my @patterns; |
108
|
10
|
|
|
|
|
19
|
eval { |
109
|
10
|
|
|
|
|
48
|
@patterns = $ignore_file->slurp( |
110
|
|
|
|
|
|
|
chomp => 1, |
111
|
|
|
|
|
|
|
iomode => '<:encoding(utf-8)', |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
}; |
114
|
|
|
|
|
|
|
|
115
|
10
|
100
|
|
|
|
9415
|
if ( @patterns ) { |
116
|
1
|
|
|
|
|
11
|
my @ignore = match_gitignore( |
117
|
|
|
|
|
|
|
[ @patterns ], |
118
|
|
|
|
|
|
|
keys %fs, |
119
|
|
|
|
|
|
|
); |
120
|
|
|
|
|
|
|
|
121
|
1
|
50
|
|
|
|
240
|
if ( @ignore ) { |
122
|
1
|
|
|
|
|
6
|
delete @fs{@ignore}; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
10
|
100
|
|
|
|
71
|
if ( %fs ) { |
127
|
|
|
|
|
|
|
print "Files found on disk but not listed in .sopm:\n", |
128
|
1
|
|
|
|
|
4
|
map{ " - $_\n" }sort keys %fs; |
|
2
|
|
|
|
|
37
|
|
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
__END__ |