forked from carlosfrodriguez/module-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckChangedFiles.pl
More file actions
executable file
·188 lines (145 loc) · 5.72 KB
/
CheckChangedFiles.pl
File metadata and controls
executable file
·188 lines (145 loc) · 5.72 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/perl
# --
# module-tools/CheckChangedFiles.pl
# - script for get changed file between different releases of OTRS
# Copyright (C) 2001-2012 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
CheckChangedFiles.pl - script for get changed file between different releases of OTRS
=head1 SYNOPSIS
CheckChangedFiles.pl -h
Get help dialog.
CheckChangedFiles.pl -r
Reduce to be checked files to core files.
CheckChangedFiles.pl -m
Path to a module where to check if files in there are affected.
CheckChangedFiles.pl [ -h | -r | -m /path/to/module ] /path/to/base/version /path/to/new/version
=head1 DESCRIPTION
Please send any questions, suggestions & complaints to <dev-support@otrs.com>
=cut
use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
use File::Find;
use Digest::MD5 qw(md5_hex);
# check if help got requested
my ( $OptHelp, $ReducedCheck, $ModulePath );
GetOptions(
'h' => \$OptHelp,
'm=s' => \$ModulePath,
'r' => \$ReducedCheck,
);
pod2usage( -verbose => 0 ) if $OptHelp;
# define whitelist for reduceded checks
my @ReducedChecks;
if ($ReducedCheck) {
@ReducedChecks = qw(Kernel bin);
}
# get given params
my $BaseVersion = shift(@ARGV);
my $NewVersion = shift(@ARGV);
# verify if the given params are not empty
die "Base version directory is not given." if !$BaseVersion;
die "New version directory is not given." if !$NewVersion;
# verify that given params are existing directories
die "Directory $BaseVersion does not exist or is not a directory." if !-d $BaseVersion;
die "Directory $NewVersion does not exist or is not a directory." if !-d $NewVersion;
if ($ModulePath) {
die "Directory $ModulePath does not exist or is not a directory." if !-d $ModulePath;
}
# get list of files and their MD5 digests
my $BaseVersionFile2MD5 = FindFilesOfVersion($BaseVersion) || {};
my $NewVersionFile2MD5 = FindFilesOfVersion($NewVersion) || {};
my $ModuleVersionFile2MD5;
if ($ModulePath) {
$ModuleVersionFile2MD5 = FindFilesOfVersion($ModulePath) || {};
}
# get list of deleted and new files
my @DeletedFiles = grep { !defined $NewVersionFile2MD5->{$_} } sort keys %{$BaseVersionFile2MD5};
my @NewFiles = grep { !defined $BaseVersionFile2MD5->{$_} } sort keys %{$NewVersionFile2MD5};
# get list of to be checked files
my %CheckFileList = %{$BaseVersionFile2MD5};
map { delete $CheckFileList{$_} } @DeletedFiles;
# get list of changed files
my @ChangedFiles = grep { $BaseVersionFile2MD5->{$_} ne $NewVersionFile2MD5->{$_} }
sort keys %CheckFileList;
# produce output if data had been gathered
if (@DeletedFiles) {
print '==============================';
print 'List of deleted files (#', scalar @DeletedFiles, '):';
map { print "\t$_" } @DeletedFiles;
}
if (@NewFiles) {
print '==============================';
print 'List of new files (#', scalar @NewFiles, '):';
map { print "\t$_" } @NewFiles;
}
if (@ChangedFiles) {
print '==============================';
print 'List of changed files (#', scalar @ChangedFiles, '):';
map { print "\t$_" } @ChangedFiles;
}
# module has been given
if ($ModuleVersionFile2MD5) {
# get list of changed files of the given module
my @ChangedModuleFiles = grep {
$ModuleVersionFile2MD5->{$_} && $ModuleVersionFile2MD5->{$_} ne $NewVersionFile2MD5->{$_}
} sort keys %CheckFileList;
print '==============================';
print 'List of changed files module (#', scalar @ChangedModuleFiles, '):';
map { print "\t$_" } @ChangedModuleFiles;
}
=item FindFilesOfVersion()
Returns a HASHREF with file names as key and its MD5 hex digest as value.
It strips out the root directory from the file name.
my $FileName2MD5 = FindFilesOfVersion( '/ws/otrs-head' );
results will look like:
$FileName2MD5 = {
'Kernel/System/Main.pm' => '7731615a697d7ed0da2579a9c71d7d9c',
};
=cut
sub FindFilesOfVersion {
my $VersionDirectory = shift;
# check directory path
return if !$VersionDirectory;
return if !-d $VersionDirectory;
# define function for traversing
my %VersionFile2MD5;
my $FindFilesOfVersion = sub {
my $FileName = $File::Find::name;
# only return valid files
return if !-f $FileName;
# have directory in, may be there CVS is contained
return if $FileName =~ m{ \A $VersionDirectory [/]? .* CVS }xms;
# get file name without root path and possible tailing '/'
my ($PackageName) = $FileName =~ m{\A $VersionDirectory (?: / )? (.*) \z}xms;
# consider customized files for OTRS 2.4 in Kernel/Custom/
$PackageName =~ s{ Kernel/Custom/ }{}xms;
# check for reduceded file checking
return if @ReducedChecks && !grep { $PackageName =~ m{\A $_ }xms } @ReducedChecks;
# create file handle for digest function
open( FH, '<', $FileName ) or return;
binmode(FH);
$VersionFile2MD5{$PackageName} = Digest::MD5->new->addfile(*FH)->hexdigest;
close(FH);
};
# start gathering filelist
find( $FindFilesOfVersion, $VersionDirectory );
return \%VersionFile2MD5;
}