[b0b0b6]: diff_dir Maximize Restore History

Download this file

diff_dir    38 lines (31 with data), 999 Bytes

#!/usr/bin/perl -w
#
# diff_dir [old_dir] [new_dir]
#
# Will look in the new_dir for new files or changed ones and then copy
# them over to the new dir.

$diff = '/usr/bin/diff -bBN';
my $dir_old = shift;
my $dir_new = shift;
my $copy    = shift || 0;

unless (-d $dir_old and -d $dir_new) { die "Usage $0 [old_dir] [new_dir]\n"; }

my @new_files = sort glob("$dir_new/*");

foreach my $f (@new_files) {
    my $file = $f;
    $file =~ s/$dir_new\///;

    if (! -r "$dir_old/$file") {
        print "$file new.\n";
        $d = 1;
        print `cp -f $f $dir_old` if $copy;
    } else {
        $d = `$diff $f $dir_old`;
        if ($d !~ /^\s*$/) {
            print "$f diffs. \n" unless $d eq '1';
            # Look for version numbers
            print "  OLD: ",`egrep -A 1 '(REVISION|LAST-UPDATED)' $dir_old/$file`;
            print "  NEW: ",`egrep -A 1 '(REVISION|LAST-UPDATED)' $dir_new/$file`;
            print `cp -f $f $dir_old` if $copy;
            print "\n";
        }
    }

}