Is there a more efficient way to get a checksum of all files in a directory?
sub print_dir {
my $dir_name = shift;
print "DIR: $dir_name\n";
opendir ( my $dir_h , "$dir_name") or die "Unable to open dir :$dir
+_name: $!\n";
while ( my $path = readdir($dir_h) ) {
next if ($path eq "." or $path eq "..");
my $full_path = "$dir_name/$path";
if ( -l $full_path) {
my $linkref = readlink($full_path);
print " LINK: $full_path ==> $linkref\n" if $opt_debug;
push(@bom_data, { Type => "symlink", Name => "$full_path", LinkR
+ef => "$linkref" });
} elsif ( -d $full_path ) {
push(@bom_data, { Type => "dir", Name => "$full_path" });
print_dir ( $full_path );
} else {
my $ctx = Digest::Adler32::XS->new();
my $file_h = IO::File->new($full_path, "r");
die "? Error: Unable to open $full_path for read: $!" if (not de
+fined($file_h));
binmode($file_h) || "? Error: Unable to set binmode on $file_h:
+$!\n";
$ctx->addfile($file_h);
$file_h->close;
my $cksum = $ctx->hexdigest;
print " FILE: $full_path ==> $cksum\n" if $opt_debug;
push(@bom_data, { Type => "file", Name => "$full_path", Checksum
+ => "$cksum"});
}
}
close $dir_h;
}
Thanks for any suggestions.
|