windows-nt/Source/XPSP1/NT/inetsrv/iis/utils/dmdiffs/dirdiff

112 lines
2.2 KiB
Plaintext
Raw Permalink Normal View History

2020-09-26 03:20:57 -05:00
use strict;
my (%old, %new);
my ($dir, $fname, $size, $dirprinted, $sectionprinted);
if((scalar @ARGV) != 2) {
die "Usage: perl dirdiff <first file> <second file>\n";
}
open(FILE, $ARGV[0]) or die "Failure to open $ARGV[0]: $!";
while(<FILE>) {
chomp;
if( ($dir, $fname, $size) = m/(.*\/)(.*) ([0-9]+$)/ ) {
$old{$dir}{$fname} = $size;
}
}
close(FILE);
open(FILE, $ARGV[1]) or die "Failure to open $ARGV[1]: $!";
while(<FILE>) {
chomp;
if( ($dir, $fname, $size) = m/(.*\/)(.*) ([0-9]+$)/ ) {
$new{$dir}{$fname} = $size;
}
}
close(FILE);
print("Files:\n");
#
# added entries
#
$sectionprinted = 0;
foreach $dir (sort keys %new) {
$dirprinted = 0;
foreach $fname (sort keys %{$new{$dir}}) {
if(!defined($old{$dir}{$fname})) {
if(!$sectionprinted) {
$sectionprinted = 1;
print(" Added:\n");
}
if(!$dirprinted) {
print(" $dir\n");
$dirprinted = 1;
}
print(" $fname\n");
}
}
}
#
# deleted entries
#
$sectionprinted = 0;
foreach $dir (sort keys %old) {
$dirprinted = 0;
foreach $fname (sort keys %{$old{$dir}}) {
if(!defined($new{$dir}{$fname})) {
if(!$sectionprinted) {
$sectionprinted = 1;
print(" Deleted:\n");
}
if(!$dirprinted) {
print(" $dir\n");
$dirprinted = 1;
}
print(" $fname\n");
}
}
}
#
# changed entries
#
$sectionprinted = 0;
foreach $dir (sort keys %old) {
$dirprinted = 0;
foreach $fname (sort keys %{$old{$dir}}) {
if(defined($new{$dir}{$fname})) {
if($new{$dir}{$fname} == $old{$dir}{$fname}) {
next;
}
if(!$sectionprinted) {
$sectionprinted = 1;
print(" Changed:\n");
}
if(!$dirprinted) {
print(" $dir\n");
$dirprinted = 1;
}
print(" $fname\n");
}
}
}