-
Notifications
You must be signed in to change notification settings - Fork 2
/
archive_diff.pl
859 lines (643 loc) · 24.7 KB
/
archive_diff.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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
#!/usr/bin/perl
# $Id$
# Copyright (c)2008 by Brian Manning <elspicyjack at gmail dot com>
#
# compare the contents of two archive files side-by-side or in list format
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 dated June, 1991.
#
# 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 General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
# FIXME
# - create a set of external modules, or call to internal Perl-ish modules
# that will list the contents of various archive formats
# - start with lzma first
=pod
=head1 NAME
B<archive_diff.pl> - compare files listed in two archives
=head1 VERSION
The CVS version of this file is $Revision$. See the top of this file for
the author's version number.
=head1 SYNOPSIS
perl archive_diff.pl -1 first_filelist.txt -2 second_filelist.txt
=head2 Script Options
--verbose|-v Verbose script output
--help|-h Show this help message
--first-file|-1st Filename of the First filelist
--second-file|-2nd Filename of the second filelist
--nocolorlog Disable colorized log output
--write|-w Write diff output to file (diff.YYYY.JJJ.XX.txt)
=head1 DESCRIPTION
B<archive_diff.pl> compares the files listed in two archives, checking for
files that are in one archive and not the other and vice versa.
=cut
#### Package 'Archive' ####
package Archive;
use Date::Parse;
use Log::Log4perl qw(get_logger);
use Moose; # comes with 'strict' and 'warnings'
use Moose::Util::TypeConstraints;
=pod
=head2 Module Archive
The Archive object grabs information from an archive of some kind and allows
this information to be queried. The L<Archive> object has the following
attributes:
=over 5
=item attrib
The archive attributes. Contained in an object of L<Archive::Attributes>
type.
=item filename
The name of the archive file. The file is checked to see if it exists and is
readable when an object is created from this class.
=item contents
A pointer to an L<Archive::FileList> object which is used to store filenames
from the archive.
=item count_pulse
How many lines to parse before the throbber (user work being done indicator)
updates itself. Defaults to 10 lines per pulse.
=back
=cut
# a subtype for holding the name of a file in the archive
# this should make it so that the file is checked when the object is created
# Str is from Moose::Util::TypeConstraints
subtype ArchiveFilename
=> as Str
=> where { ( -r $_ ) };
has q(attrib) => ( is => q(rw), isa => q(Archive::Attributes));
has q(archfilename) => (is => q(rw), isa => q(ArchiveFilename), required => 1);
has q(filelist) => ( is => q(rw), isa => q(Archive::FileList) );
has q(count_pulse) => ( is => q(rw), isa => q(Int), default => 10 );
=pod
=head3 BUILD()
This method is called automatically, it initializes the L<Archive::FileList>
object so it can store individual L<Archive::File> records.
=cut
sub BUILD {
my $self = shift;
my $logger = get_logger();
$logger->debug(q(Entering Archive->BUILD() ));
$self->filelist(Archive::FileList->new());
} # sub BUILD
=pod
=head3 parse()
Parses (lists) the contents of the archive, and populates the appropriate
object attributes.
=cut
sub parse {
my $self = shift;
my $total_lines;
my $logger = get_logger();
# open the file and read it's contents
open(FH, q(<) . $self->archfilename);
my $throbber = Throbber->new( count_pulse => $self->count_pulse() );
# turn off line buffering on STDOUT
$| = 1;
while (<FH>) {
my $line = $_;
# skip blank lines
next if ( $line =~ /^$/ );
# if the line starts with a date string
if ( $line =~ /^\d\d\d\d-\d\d-\d\d/ ) {
chomp($line);
# found a file entry
$line =~ s/ +/ /g;
$line =~ s/\r$//g;
my @splitline = split(/ /, $line);
if ( $logger->is_debug() ) {
$logger->debug(join(q(:), @splitline));
$logger->debug(q(this line has ) . scalar(@splitline)
. q( fields));
} # if ( $logger->is_debug() )
# create the archive file object
my $archive_file = Archive::File->new(
# str2time comes from Date::Parse
timestamp => str2time($splitline[0] . q( ) . $splitline[1]),
attributes => $splitline[2],
orig_size => $splitline[3],
);
# some records have 5 fields, some have 6 (extra field is
# compressed file size). compensate
if ( scalar(@splitline) == 5 ) {
$archive_file->{name} = $splitline[4];
} elsif ( scalar(@splitline) == 6 ) {
$archive_file->{comp_size} = $splitline[4];
$archive_file->{name} = $splitline[5];
} else {
$logger->fatal(q(Too many arguments in archive file output));
exit 1;
} # if ( scalar(@splitline) == 5 )
$logger->debug(q(Adding ) . $archive_file->name
. q( to filelist object));
$self->filelist->add( key => $archive_file->name(),
object => $archive_file );
$logger->debug(q(there are now ) . $self->filelist->get_count()
. q( records in self->filelist));
$total_lines++;
$throbber->throb(total_lines => $total_lines);
} # if ( $line =~ /^\d\d\d\d-\d\d-\d\d/ )
} # while (<FH>)
$logger->info(qq(Total files in archive: ) . $total_lines);
# turn line buffering back on on STDOUT
$| = 0;
} # sub parse
#### end Package 'Archive' ####
#### Package 'Archive::Diff' ####
package Archive::Diff;
use Log::Log4perl qw(get_logger);
use Moose; # comes with 'strict' and 'warnings'
use Moose::Util::TypeConstraints;
use Time::Local;
=pod
=head2 Module Archive::Diff
This object takes two L<Archive> objects as arguments, and when queried using
the object methods, will return a formatted list that shows the differences in
the contents of the two archives. This module has the following attributes:
=over 5
=item first
The first archive to be compared.
=item second
The second archive to be compared.
=item common
An archive that contains a list of files that are common to both the first and
second archives.
=back
=cut
has q(first) => ( is => q(rw), isa => q(Archive), required => 1 );
has q(second) => ( is => q(rw), isa => q(Archive), required => 1 );
has q(common) => ( is => q(rw), isa => q(Archive::FileList) );
=pod
=head3 BUILD()
Initializes the common L<Archive::FileList> object.
=cut
sub BUILD {
my $self = shift;
$self->common( Archive::FileList->new() );
} # sub BUILD
=pod
=head3 simple_stats()
Shows simple statistics about each file contained inside of the
L<Archive::Diff> object.
=cut
sub simple_stats {
my $self = shift;
my $logger = get_logger();
$logger->info(q(The first filename is:));
$logger->info($self->first->archfilename);
$logger->info(q(The second filename is:));
$logger->info($self->second->archfilename);
$logger->info(q(There are ) . $self->first->filelist->get_count()
. qq( files in the first Archive object));
$logger->info(q(There are ) . $self->second->filelist->get_count()
. qq( files in the second Archive object));
$logger->info(q(There are ) . $self->common->get_count()
. qq( files in the 'common' Archive object));
} # sub simple_diff
=pod
=head3 simple_diff()
Compares the lists of files in the first and second archive objects, prints
three lists; the list of common files, the list of files in the first object
only, and the list of files in the second object only.
=cut
sub simple_diff {
my $self = shift;
my $logger = get_logger();
$logger->info(q(Running a diff on the first and second files...));
# get a list of files from the first filelist
foreach my $firstkey ( $self->first->filelist->get_keys() ) {
# for each file in that list, see if the same file exists in the
# second filelist
$logger->debug(qq(simple_diff: Checking $firstkey));
if ( $self->second->filelist->exists(key => $firstkey) ) {
$logger->debug(qq(do_diff: matched $firstkey));
$self->common->add(
filename => $firstkey,
object => $self->first->filelist->get( key => $firstkey ),
);
$self->first->filelist->del(key => $firstkey);
$self->second->filelist->del(key => $firstkey);
} # if ( $self->second->exists(key => $firstkey)
} # foreach my $firstkey ( $self->first->get_keys() )
} # sub do_diff
#### end Package 'Archive::Diff' ####
#### Package 'Archive::Attributes' ####
package Archive::Attributes;
use Moose; # comes with 'strict' and 'warnings'
use Moose::Util::TypeConstraints;
=pod
=head2 Module Archive::Attributes
Contains metadata attributes for an archive file.
=over 5
=item version
The version of the program that created this archive. May or may not come from
the archive itself; an asterisk B<*> denotes the version number of the program
on the system, as the archive itself does not hold any version information.
=back
=cut
has q(version) => ( is => q(rw), isa => q(Str) );
#### end Package 'Archive::Attributes' ####
#### Package 'Archive::FileList' ####
package Archive::FileList;
use Log::Log4perl qw(get_logger);
use Moose; # comes with 'strict' and 'warnings'
use Moose::Util::TypeConstraints;
=pod
=head2 Module Archive::FileList
An object that keeps a list of L<Archive::File> objects keyed by filename.
The object has the following attributes:
=over 5
=item _filelist
An internal holder of the file list hash. Use the get_keys() method to obtain
the list of files being held by this hash.
=back
=cut
has q(_filelist) => ( is => q(rw), isa => q(HashRef) );
=pod
=head3 BUILD
This method is called automatically, it initializes the _filelist hash.
=cut
sub BUILD {
my $self = shift;
my $logger = get_logger();
$logger->debug(q(Entering Archive::FileList->BUILD));
$self->_filelist({});
} # sub BUILD
=pod
=head3 add([key|filename] => $filename, [object|value] => Archive::File object)
Adds a file from the archive to the L<Archive::FileList> object using the
filename as a key and the L<Archive::File> object as the value.
=cut
sub add {
my $self = shift;
my %args = @_;
my $logger = get_logger();
my ($filename, $fileobj);
my %filelist = %{$self->_filelist()};
# since we support two different signatures for passing in the
# Archive::File object...
if ( exists $args{key} ) { $filename = $args{key}; }
if ( exists $args{filename} ) { $filename = $args{filename}; }
if ( exists $args{value} ) { $fileobj = $args{value}; }
if ( exists $args{object} ) { $fileobj = $args{object}; }
die q(File name/object not passed in to add method)
unless ( defined $fileobj && defined $filename );
# verify we got an Archive::File object; blessed is imported from Moose
my $fileobj_type = blessed $fileobj;
if ( $fileobj_type eq q(Archive::File) ) {
# now see if that filename is already in the file list
if ( exists($filelist{$filename}) ) {
# yes, it exists; throw a warning
$logger->warn(q(File: ) . $fileobj->name());
$logger->warn(q( already exists in filelist));
} else {
# no, it doesn't exist; add it
$filelist{$filename} = $fileobj;
# reassign the temp list to the object
$self->_filelist({%filelist});
} # if ( exists($filehash{$fileobj->name()} )
} # if ( $fileobj_type eq q(Archive::File) )
} # sub add
=pod
=head3 del([key|filename] => $filename)
Deletes a file from the L<Archive::FileList> object using the filename as a
key.
=cut
sub del {
my $self = shift;
my %args = @_;
my $logger = get_logger();
my ($filename);
my %filelist = %{$self->_filelist()};
# since we support two different signatures for passing in the
# Archive::File object...
if ( exists $args{key} ) { $filename = $args{key}; }
if ( exists $args{filename} ) { $filename = $args{filename}; }
die q(File name/object not passed in to add method)
unless ( defined $filename );
# verify we got an Archive::File object; blessed is imported from Moose
if ( exists($filelist{$filename}) ) {
# yes, it exists; delete the key
delete $filelist{$filename};
# reassign the temp list to the object
$self->_filelist({%filelist});
} else {
# no, it doesn't exist; throw an error
$logger->error(qq(key $filename));
$logger->error(q(does not exists in the filelist));
} # if ( exists($filelist{$filename}) )
} # sub del
=pod
=head3 delete([key|filename] => $filename)
A synonym for the B<del()> method.
=cut
sub delete {
my $self = shift;
$self->del(@_);
} # sub delete
=pod
=head3 get_count()
Returns a count of how many L<Archive::File> objects are currently being
stored in the L<Archive::FileList> object.
=cut
sub get_count {
my $self = shift;
my %filelist = %{$self->_filelist};
return scalar(keys(%filelist));
} # sub count
=pod
=head3 get_keys()
Returns a sorted list of filenames that are stored inside the
L<Archive::FileList> object.
=cut
sub get_keys {
my $self = shift;
return sort($self->get_unsorted_keys);
} # sub keys
=pod
=head3 get_unsorted_keys()
Returns an unsorted list of filenames that are stored inside the
L<Archive::FileList> object.
=cut
sub get_unsorted_keys {
my $self = shift;
my %filelist = %{$self->_filelist};
return keys(%filelist);
} # sub unsorted_keys
=pod
=head3 get([key|filename] => $key)
Returns the L<Archive::File> object specified by the contents of $key. Will
throw a warning if there is no L<Archive::File> object stored that matches the
$key.
=cut
sub get {
my $self = shift;
my %args = @_;
my $logger = get_logger();
my ($filename, $fileobj);
my %filelist = %{$self->_filelist()};
# since we support two different signatures for passing in the
# Archive::File object...
if ( exists $args{key} ) { $filename = $args{key}; }
if ( exists $args{filename} ) { $filename = $args{filename}; }
if ( exists $filelist{$filename} ) {
return $filelist{$filename};
} else {
$logger->warn(qq(key $filename));
$logger->warn(q(does not exist in filelist));
return 0;
} # if ( exists $filelist{$filename} )
} # sub get
=pod
=head3 exists([key|filename] => $key)
Returns false by default. Returns true if the string specified in $key is an
L<Archive::File> object is in the filelist.
=cut
sub exists {
my $self = shift;
my %args = @_;
my $logger = get_logger();
my ($filename, $fileobj);
my %filelist = %{$self->_filelist()};
# since we support two different signatures for passing in the
# Archive::File object...
if ( exists $args{key} ) { $filename = $args{key}; }
if ( exists $args{filename} ) { $filename = $args{filename}; }
if ( exists $filelist{$filename} ) {
return 1;
} else {
return 0;
} # if ( exists $filelist{$filename} )
} # sub get
#### end Package 'Archive::FileList' ####
#### Package 'Archive::File' ####
package Archive::File;
use Moose; # comes with 'strict' and 'warnings'
use Moose::Util::TypeConstraints;
=pod
=head2 Module Archive::File
An object that holds information about a file in an archive. You would most
likely create as many L<Archive::File> objects as you had individual files and
directories in an archive. L<Archive::File> has the following attributes:
=over 5
=item timestamp
The timestamp of the file as stored in the archive.
=item attributes
The attributes stored with the file in the archive.
=item orig_size
The uncompressed size of the file stored in the archive.
=item comp_size
The compressed size of the file (if given by the compression program)
=item name
The name of the file that is a member of this L<Archive>.
=back
=cut
# these are stored in the order that they are retrieved from a 7zip archive
has q(timestamp) => ( is => q(rw), isa => q(Int) );
has q(attributes) => ( is => q(rw), isa => q(Str) );
has q(orig_size) => ( is => q(rw), isa => q(Int) );
has q(comp_size) => ( is => q(rw), isa => q(Int) );
has q(name) => ( is => q(rw), isa => q(Str) );
#### end Package 'Archive::File' ####
#### Package 'Throbber' ####
package Throbber;
use Moose; # comes with 'strict' and 'warnings'
=pod
=head2 Module Throbber
Moves some text on the screen while processing is going on in the background.
The L<Throbber> object has the following attributes:
=over 5
=item count_pulse
How many changes in state before generating a 'pulse' that is visible to the
user.
=item _beats
How many changes in state that have occured since the last 'pulse'.
=back
=cut
has q(count_pulse) => ( is => q(rw), isa => q(Int), default => 10 );
has q(_beats) => ( is => q(rw), isa => q(Int), default => 1);
=pod
=head3 throb($number)
Tells the L<Throbber> object to see if it needs to manipulate the text on the
screen. The L<Throbber> object does this so the user knows that the computer
is busy processing data. The $number value is the number of lines processed
so far.
=cut
sub throb {
my $self = shift;
my %args = @_;
if ( defined $args{total_lines} ) {
if ( ( $args{total_lines} % $self->count_pulse() ) == 0 ) {
print qq(self->_beats is ) . $self->_beats() . qq(\r);
if ( $self->_beats == 1 ) { print q(- ); }
elsif ( $self->_beats == 2 ) { print q(\ ); }
elsif ( $self->_beats == 3 ) { print q(| ); }
elsif ( $self->_beats == 4 ) {
print q(/ );
# reset the throbber beat counter
$self->_beats(0);
} # if ( $self->_beats == 1 )
$self->_beats($self->_beats() + 1);
print q(Total Lines counted: ) . $args{total_lines} . qq(\r);
} # if ( ( $args{total_lines} % $self->count_pulse() ) == 0 )
} # if ( defined $args{total_lines} )
} # sub throb
#### end Package 'Throbber' ####
#### Package 'main' ####
package main;
use strict;
use warnings;
use Getopt::Long;
use Log::Log4perl qw(get_logger);
use Log::Log4perl::Level;
use Pod::Usage;
my ($VERBOSE, $first_file, $second_file, $first_obj, $second_obj,
$write_diffs, $colorlog, $diff_list);
# colorize Log4perl output by default
$colorlog = 1;
# show the diff report output by default
$diff_list = 1;
my $goparse = Getopt::Long::Parser->new();
$goparse->getoptions( q(verbose|v) => \$VERBOSE,
q(help|h) => \&ShowHelp,
q(first-file|first|1st|1=s) => \$first_file,
q(second-file|second|2nd|2=s) => \$second_file,
q(colorlog!) => \$colorlog,
q(write|w) => \$write_diffs,
q(difflist|dl!) => \$diff_list,
); # $goparse->getoptions
# always turn off color logs under Windows, the terms don't do ANSI
if ( $^O =~ /MSWin32/ ) { $colorlog = 0; }
# set up the logger
my $logger_conf = qq(log4perl.rootLogger = INFO, Screen\n);
if ( $colorlog ) {
$logger_conf .= qq(log4perl.appender.Screen = )
. qq(Log::Log4perl::Appender::ScreenColoredLevels\n);
} else {
$logger_conf .= qq(log4perl.appender.Screen = )
. qq(Log::Log4perl::Appender::Screen\n);
} # if ( $Config->get(q(colorlog)) )
$logger_conf .= qq(log4perl.appender.Screen.stderr = 1\n)
. qq(log4perl.appender.Screen.layout = PatternLayout\n)
. q(log4perl.appender.Screen.layout.ConversionPattern = %d %p %m%n)
. qq(\n);
#log4perl.appender.Screen.layout.ConversionPattern = %d %p> %F{1}:%L %M - %m%n
# create the logger object
Log::Log4perl::init( \$logger_conf );
my $logger = get_logger("");
# change the log level from INFO if the user requests more gar-bage
if ( $VERBOSE ) { $logger->level($DEBUG); }
# check to make sure we can read the input files
# if they're both readable, read them and bless them into objects
if ( defined $first_file ) {
# read in the file and bless it into an Archive object
$first_obj = eval { Archive->new( archfilename => $first_file ); };
if ( $@ ) { &FileReadDie($@); }
} else {
$logger->fatal(q(First file not specified with --first-file switch));
&HelpDie;
} # if ( defined $first_file )
if ( defined $second_file ) {
# read in the file and bless it into an Archive object
$second_obj = eval { Archive->new( archfilename => $second_file ); };
if ( $@ ) { &FileReadDie($@); }
} else {
$logger->fatal(q(Second file not specified with --second-file switch));
&HelpDie;
} # if ( defined $first_file )
$logger->info(qq(=-=-=-=-=-= Begin $0 =-=-=-=-=-=));
$logger->info(qq(Parsing first archive file));
$first_obj->parse();
$logger->info(qq(Parsing second archive file));
$second_obj->parse();
$logger->info(qq(=-=-=-=-=-= Archive Diff Report =-=-=-=-=-=));
my $diff = Archive::Diff->new( first => $first_obj, second => $second_obj );
$logger->info(qq(=-=-=-=-=-= 'Before' Report =-=-=-=-=-=));
$diff->simple_stats();
$diff->simple_diff();
$logger->info(qq(=-=-=-=-=-= 'After' Report =-=-=-=-=-=));
$diff->simple_stats();
# print to the screen first
if ( $diff_list ) {
$logger->info(qq(=-=-=-=-=-= Common File List =-=-=-=-=-=));
foreach ( $diff->common->get_keys() ) { $logger->info($_); }
$logger->info(qq(=-=-=-=-=-= 'First' File List =-=-=-=-=-=));
foreach ( $diff->first->filelist->get_keys() ) { $logger->info($_); }
$logger->info(qq(=-=-=-=-=-= 'Second' File List =-=-=-=-=-=));
foreach ( $diff->second->filelist->get_keys() ) { $logger->info($_); }
} # if ( $diff_list )
if ( $write_diffs ) {
# get the date for creating an output file
my $date = qx/date +%Y.%j/;
chomp($date);
my $outfile;
# loop across these numbers in order to find a free filename
foreach ( 1..99 ) {
$outfile = q(diffs.) . $date . sprintf(q(.%02d), $_) . q(.txt);
if ( ! -e $outfile ) { last; }
} # foreach ( 1..99 )
# found a free filename, open the filehandle and write the diff file
$logger->info(qq(Writing diff list output to $outfile));
open(DIFF_FH, q(>) . $outfile);
# files common between both objects
print DIFF_FH qq(=-=-=-=-=-= Common File List =-=-=-=-=-=\n);
foreach ( $diff->common->get_keys() ) { print DIFF_FH $_ . qq(\n); }
# files that are only in the first object
print DIFF_FH qq(=-=-=-=-=-= 'First' File List =-=-=-=-=-=\n);
print DIFF_FH qq(First file name:\n);
print DIFF_FH $diff->first->archfilename() . qq(\n);
foreach ( $diff->first->filelist->get_keys() ) {
print DIFF_FH $_ . qq(\n);
} # foreach ( $diff->first->filelist->get_keys() )
# files that are only in the second object
print DIFF_FH qq(=-=-=-=-=-= 'Second' File List =-=-=-=-=-=\n);
print DIFF_FH qq(Second file name:\n);
print DIFF_FH $diff->second->archfilename() . qq(\n);
foreach ( $diff->second->filelist->get_keys() ) {
print DIFF_FH $_ . qq(\n);
} # foreach ( $diff->second->filelist->get_keys() )
# we're done, close the filehandle
close(DIFF_FH);
} # if ( $write_diffs )
exit 0;
sub HelpDie {
my $logger = get_logger();
$logger->fatal(qq(Use '$0 --help' to view script options));
exit 1;
} # sub HelpDie
sub FileReadDie {
my $error_msg = shift;
my $logger = get_logger();
$logger->fatal(qq(Hmmm, something happened trying to read a file));
if ( $logger->is_debug() ) {
print $error_msg;
} else {
$logger->fatal(qq(Use --verbose for more error output));
} # if ( $logger->is_debug() )
&HelpDie;
} # sub FileReadDie
# simple help subroutine
sub ShowHelp {
# shows the POD documentation (short or long version)
my $whichhelp = shift; # retrieve what help message to show
shift; # discard the value
# call pod2usage and have it exit non-zero
# if if one of the 2 shorthelp options were not used, call longhelp
if ( ($whichhelp eq q(help)) || ($whichhelp eq q(h)) ) {
pod2usage(-exitstatus => 1);
} else {
pod2usage(-exitstatus => 1, -verbose => 2);
} # if ( ($whichhelp eq q(help)) || ($whichhelp eq q(h)) )
} # sub ShowHelp
#### end Package main ####
=pod
=head1 AUTHOR
Brian Manning E<lt>elspicyjack at gmail dot comE<gt>
=cut
# vi: set sw=4 ts=4:
# end of line