line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#================================ Report.pm =================================== |
2
|
|
|
|
|
|
|
# Filename: Report.pm |
3
|
|
|
|
|
|
|
# Description: Generate reports from a FileHash. |
4
|
|
|
|
|
|
|
# Original Author: Dale M. Amon |
5
|
|
|
|
|
|
|
# Revised by: $Author: amon $ |
6
|
|
|
|
|
|
|
# Date: $Date: 2008-08-28 23:35:28 $ |
7
|
|
|
|
|
|
|
# Version: $Revision: 1.8 $ |
8
|
|
|
|
|
|
|
# License: LGPL 2.1, Perl Artistic or BSD |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
#============================================================================= |
11
|
1
|
|
|
1
|
|
462
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
12
|
1
|
|
|
1
|
|
18
|
use Fault::Logger; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
17
|
|
13
|
1
|
|
|
1
|
|
4
|
use FileHash::Base; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
package FileHash::Report; |
16
|
1
|
|
|
1
|
|
4
|
use vars qw{@ISA}; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
386
|
|
17
|
|
|
|
|
|
|
@ISA = qw( UNIVERSAL ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#============================================================================= |
20
|
|
|
|
|
|
|
# INTERNAL METHODS |
21
|
|
|
|
|
|
|
#============================================================================= |
22
|
|
|
|
|
|
|
# Print the contents of a hash bucket, one file to a line and an extra newline |
23
|
|
|
|
|
|
|
# after the block if the flg is set. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _print_bucket ($$$*$) { |
26
|
0
|
|
|
0
|
|
|
my ($self,$v1,$report,$fd,$flg) = @_; |
27
|
0
|
|
|
|
|
|
my ($j,$ok); |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
foreach $j (@$v1) { |
30
|
0
|
|
|
|
|
|
$ok = printf $fd "%s %12s %12s %s\n", |
31
|
|
|
|
|
|
|
$j->md5sum, $j->sizeBytes, $j->mtime,$j->path; |
32
|
0
|
0
|
|
|
|
|
$ok or Fault::Logger->log_once ("Failed to print to '$report': $!"); |
33
|
|
|
|
|
|
|
} |
34
|
0
|
0
|
|
|
|
|
if ($flg) { |
35
|
0
|
|
|
|
|
|
$ok = printf $fd "\n"; |
36
|
0
|
0
|
|
|
|
|
$ok or Fault::Logger->log_once ("Failed to print to '$report': $!"); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#============================================================================= |
41
|
|
|
|
|
|
|
# CLASS METHODS |
42
|
|
|
|
|
|
|
#============================================================================= |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
0
|
1
|
|
sub new ($) {my ($class) = @_; return bless {}, $class;} |
|
0
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
#============================================================================= |
47
|
|
|
|
|
|
|
# INSTANCE METHODS |
48
|
|
|
|
|
|
|
#============================================================================= |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub all (\%$$$) { |
51
|
0
|
|
|
0
|
1
|
|
my ($self,$files,$report,$fmtflg) = @_; |
52
|
0
|
|
|
|
|
|
my ($i,$j,$fd); |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
defined $fmtflg or $fmtflg=0; |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
if ($::DEBUG) { |
57
|
0
|
0
|
|
|
|
|
Fault::Logger->arg_check_isa ($files,"FileHash::Base","files") |
58
|
|
|
|
|
|
|
or return undef; |
59
|
0
|
0
|
|
|
|
|
Fault::Logger->arg_check_noref ($report,"reportname") |
60
|
|
|
|
|
|
|
or return undef; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Fault::Logger->assertion_check |
64
|
0
|
0
|
|
|
|
|
(!(open $fd, ">$report"),undef,"Can not open '$report': $!") |
65
|
|
|
|
|
|
|
or return undef; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my $ok; |
68
|
0
|
|
|
|
|
|
foreach $i (values %{$files->{'filehash'}}) { |
|
0
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$self->_print_bucket ($i,$report,$fd,$fmtflg); |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
|
close ($fd); |
72
|
0
|
|
|
|
|
|
return $self; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
#============================================================================= |
76
|
|
|
|
|
|
|
# POD DOCUMENTATION |
77
|
|
|
|
|
|
|
#============================================================================= |
78
|
|
|
|
|
|
|
# You may extract and format the documention section with the 'perldoc' cmd. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 NAME |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
FileHash::Report - Generate reports from a FileHash. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 SYNOPSIS |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
use FileHash::Report; |
87
|
|
|
|
|
|
|
$obj = FileHash::Report->new; |
88
|
|
|
|
|
|
|
$obj = $obj->all ($filehash,$report,$fmtflg) |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 Inheritance |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
UNIVERSAL |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 Description |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Write simple reports. The output data is printed in search key/bucket order. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 Examples |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
use FileHash::Content; |
101
|
|
|
|
|
|
|
use FileHash::Report; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $r = FileHash::Report->new; |
104
|
|
|
|
|
|
|
my $a = FileHash::Content->alloc; |
105
|
|
|
|
|
|
|
$a->initFromTree ("/root"); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# print a list of all sets of files with the same md5sum and size. |
108
|
|
|
|
|
|
|
my $c = $a->identical; |
109
|
|
|
|
|
|
|
$r->all ($c,"myreport"); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# Hash the data by name instead. |
112
|
|
|
|
|
|
|
my $b = FileHash::Name->alloc; |
113
|
|
|
|
|
|
|
$b->initFromTree ($a); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# print a list of all sets of files with the same file name. |
116
|
|
|
|
|
|
|
$c = $b->identical; |
117
|
|
|
|
|
|
|
$r->all ($c,"myreport2"); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# Print a list of all files found in a that are not in b |
120
|
|
|
|
|
|
|
$a = FileHash::Content->alloc; |
121
|
|
|
|
|
|
|
$b = FileHash::Content->alloc; |
122
|
|
|
|
|
|
|
$a->initFromTree ("/home/me/tree1"); |
123
|
|
|
|
|
|
|
$b->initFromTree ("/home/me/tree2"); |
124
|
|
|
|
|
|
|
$c = $a->andnot ($b); |
125
|
|
|
|
|
|
|
$r->all ($c,"myreport3"); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# Print a list of all files found in a that are in one or the |
128
|
|
|
|
|
|
|
# other but not both. |
129
|
|
|
|
|
|
|
my $c = $a->xor ($b); |
130
|
|
|
|
|
|
|
$r->all ($c,"myreport3"); |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 Class Variables |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
None. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 Instance Variables |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
None. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 Class Methods |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=over 4 |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item B<$obj = FileHash::Report-Enew> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Create instances of FileHash::Report. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 Instance Methods |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Methods return self on success and undef on error unless stated otherwise. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=over 4 |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
A 'group of files' are files that have the same hash key. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item B<$obj = $obj-Eall ($filehash,$report,$fmtflg)> |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Write a report of all files in $filehash to a file named $report. If |
159
|
|
|
|
|
|
|
the format flag exists and is true, linefeeds are printed between each |
160
|
|
|
|
|
|
|
group on output. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=back 4 |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 Private Class Method |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
None. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 Private Instance Methods |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
None. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 Errors and Warnings |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Lots. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 KNOWN BUGS |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
See TODO. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 SEE ALSO |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
FileHash::Base, Fault::Logger. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 AUTHOR |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Dale Amon |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
#============================================================================= |
191
|
|
|
|
|
|
|
# CVS HISTORY |
192
|
|
|
|
|
|
|
#============================================================================= |
193
|
|
|
|
|
|
|
# $Log: Report.pm,v $ |
194
|
|
|
|
|
|
|
# Revision 1.8 2008-08-28 23:35:28 amon |
195
|
|
|
|
|
|
|
# perldoc section regularization. |
196
|
|
|
|
|
|
|
# |
197
|
|
|
|
|
|
|
# Revision 1.7 2008-08-04 12:13:46 amon |
198
|
|
|
|
|
|
|
# Moved logical unary and binary ops to FileHash; created an internal common hash bucket print method. |
199
|
|
|
|
|
|
|
# |
200
|
|
|
|
|
|
|
# Revision 1.6 2008-07-27 15:16:17 amon |
201
|
|
|
|
|
|
|
# Wrote lexical parse for Entry; error checking on eval and other minor issues. |
202
|
|
|
|
|
|
|
# |
203
|
|
|
|
|
|
|
# Revision 1.5 2008-07-25 14:30:42 amon |
204
|
|
|
|
|
|
|
# Documentation improvements and corrections. |
205
|
|
|
|
|
|
|
# |
206
|
|
|
|
|
|
|
# Revision 1.4 2008-07-24 20:19:43 amon |
207
|
|
|
|
|
|
|
# Just in case I missed anything. |
208
|
|
|
|
|
|
|
# |
209
|
|
|
|
|
|
|
# Revision 1.3 2008-07-24 13:35:26 amon |
210
|
|
|
|
|
|
|
# switch to NeXT style alloc/init format for FileHash and Entry classes. |
211
|
|
|
|
|
|
|
# |
212
|
|
|
|
|
|
|
# Revision 1.2 2008-07-23 21:12:24 amon |
213
|
|
|
|
|
|
|
# Moved notes out of file headers; a few doc updates; added assertion checks; |
214
|
|
|
|
|
|
|
# minor bug fixes. |
215
|
|
|
|
|
|
|
# |
216
|
|
|
|
|
|
|
# $DATE Dale Amon |
217
|
|
|
|
|
|
|
# Created. |
218
|
|
|
|
|
|
|
1; |