Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

111 lines
2.3 KiB

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");
}
}
}