forked from OTRS/module-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileListCheck.pl
executable file
·140 lines (114 loc) · 4.28 KB
/
FileListCheck.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/perl
# --
# module-tools/FileListCheck.pl
# - script for checking the file list in the .sopm file
# Copyright (C) 2001-2013 OTRS AG, http://otrs.org/
# --
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU AFFERO General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# or see http://www.gnu.org/licenses/agpl.txt.
# --
=head1 NAME
FileListCheck.pl - script for checking completeness of the file list in OPMS-files of packages.
=head1 SYNOPSIS
FileListCheck.pl -h
FileListCheck.pl /path/to/module
FileListCheck.pl /path/to/module -s # include symlinked directories
=head1 DESCRIPTION
Please send any questions, suggestions & complaints to <[email protected]>
=cut
use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
use File::Basename;
use File::Find;
# check if help got requested
my $OptHelp;
my $OptSymlink;
GetOptions(
'h' => \$OptHelp,
's' => \$OptSymlink,
);
pod2usage( -verbose => 0 ) if $OptHelp;
# check if directory exists
my $ModuleDirectory = shift;
die "Module directory not given!" if !$ModuleDirectory;
die "Module directory does not exist or is not a directory!" if !-d $ModuleDirectory;
# get name of module and check for existence
$ModuleDirectory =~ s{ /+ \z }{}xms;
my $ModuleName = basename($ModuleDirectory);
my $SOPMFileName = $ModuleName . '.sopm';
my $SOPMFilePath = join '/', ( $ModuleDirectory, $SOPMFileName );
die "Couldn't find file '$SOPMFileName' in $ModuleDirectory - wrong directory?"
if !-f $SOPMFilePath;
# get encoding of XML file
my $SOPMEncoding;
open my $EncFH, '<', $SOPMFilePath;
LINE:
while ( my $Line = <$EncFH> ) {
($SOPMEncoding) = $Line =~ m{ encoding="( (?: iso | utf ) - .* )" }xms;
last LINE;
}
# set default encoding to UTF8
$SOPMEncoding ||= 'utf8';
# strip out dash(es) in encoding
$SOPMEncoding =~ s{ - }{}gxms;
my $FileMode = ":encoding($SOPMEncoding)";
# open file and set proper encoding for reading
die "Couldn't read from '$SOPMFilePath'!" if !open( my $FH, '<', $SOPMFilePath );
binmode( $FH, $FileMode );
# read only file list entries from sopm file
my @FileList;
while ( my $Line = <$FH> ) {
if (
$Line =~ m{ \A \s* <File .+ Location="( [^"]+ )" }xms
&& $1 !~ m{ \.dia \z }xms
)
{
push @FileList, $1;
}
}
close($FH);
# get current files of module
my @ModuleFiles;
my $ModuleFinder = sub {
my $FileName = $File::Find::name;
return if !-f $FileName;
return if $FileName =~ m{\.project}xms;
return if $FileName =~ m{\.includepath}xms;
return if $FileName =~ m{\.settings}xms;
return if $FileName =~ m{SVN}xms;
return if $FileName =~ m{\.svn}xms;
return if $FileName =~ m{CVS}xms;
return if $FileName =~ m{ $SOPMFileName \z}xms;
return if $FileName =~ m{ \. dia \z }xms;
push @ModuleFiles, $FileName;
};
find( { wanted => $ModuleFinder, follow => $OptSymlink }, $ModuleDirectory );
# get listed but not existing files
my @MissingFiles = grep { !-f $ModuleDirectory . '/' . $_ } @FileList;
# get rid of trailing module path
@ModuleFiles = grep { $_ =~ s{\A \Q$ModuleDirectory/\E }{}xms } @ModuleFiles;
# get missing file list entries
my %ModuleFileInFileList = map { $_ => 0 } @ModuleFiles;
map { $ModuleFileInFileList{$_} = 1 } @FileList;
my @MissingFileListEntries = grep { $ModuleFileInFileList{$_} == 0 } keys %ModuleFileInFileList;
# generate output
map { print "File '$_' is listed in SOPM, but missing in file system!\n" } @MissingFiles;
map { print "File '$_' is in the file system, but missing in the SOPM!\n" } @MissingFileListEntries;
print "###############################\n";
print "# Insert this into your sopm! #\n";
print "###############################\n";
map { print " <File Permission=\"644\" Location=\"$_\"\/>\n" } sort @MissingFileListEntries;