| version 1.5, 2005/07/10 22:17:13 |
version 1.6, 2005/07/24 21:40:48 |
|
|
| # |
# |
| # |
# |
| |
|
| # $Platon: scripts/perl/filesystem/hardlink-files.pl,v 1.4 2005/05/24 15:43:00 rajo Exp $ |
# $Platon: scripts/perl/filesystem/hardlink-files.pl,v 1.5 2005/07/10 22:17:13 rajo Exp $ |
| |
|
| use strict; |
use strict; |
| |
|
| Line 30 use Cwd qw( abs_path ); |
|
| Line 30 use Cwd qw( abs_path ); |
|
| use File::Basename qw( basename fileparse ); |
use File::Basename qw( basename fileparse ); |
| use Digest::MD5; |
use Digest::MD5; |
| #use Digest::SHA1; |
#use Digest::SHA1; |
| use Data::Dumper; |
#use Data::Dumper; |
| |
use XML::Dumper; |
| use Time::HiRes qw(gettimeofday tv_interval); |
use Time::HiRes qw(gettimeofday tv_interval); |
| |
|
| $| = 1; |
$| = 1; |
|
|
| *file *dir *prune |
*file *dir *prune |
| $md5sums $cache $stat $stat_global $mountpoints |
$md5sums $cache $stat $stat_global $mountpoints |
| @directories |
@directories |
| |
$dump |
| ); |
); |
| |
|
| unless (scalar(@ARGV)) { |
unless (scalar(@ARGV)) { |
| Line 48 unless (scalar(@ARGV)) { |
|
| Line 50 unless (scalar(@ARGV)) { |
|
| exit 1; |
exit 1; |
| } |
} |
| |
|
| $cache_file = ".hardlink-cache"; |
$dump = new XML::Dumper; |
| |
|
| |
$cache_file = ".hardlink-cache.xml"; |
| $start = [gettimeofday]; |
$start = [gettimeofday]; |
| |
|
| *file = *File::Find::name; |
*file = *File::Find::name; |
| Line 144 foreach my $xdir (@directories) { # {{{ |
|
| Line 148 foreach my $xdir (@directories) { # {{{ |
|
| my $file = "$xdir/$cache_file"; |
my $file = "$xdir/$cache_file"; |
| if (-f $file) { |
if (-f $file) { |
| print "Trying to load cache file '$file' ... "; |
print "Trying to load cache file '$file' ... "; |
| my $code; |
my $hardlink_cache = $dump->xml2pl($file); |
| if (open(FILE, $file)) { |
if (defined $hardlink_cache and ref($hardlink_cache) eq 'HASH') { |
| while(<FILE>) { |
$cache->{$xdir} = $hardlink_cache; |
| $code .= $_; |
print "OK\n" |
| } |
|
| close(FILE); |
|
| my $hardlink_cache = undef; |
|
| eval $code; |
|
| if ($@) { |
|
| print "failed: $@; ... removing\n"; |
|
| unlink $file; |
|
| } |
|
| if (defined $hardlink_cache and ref($hardlink_cache) eq 'HASH') { |
|
| $cache->{$xdir} = $hardlink_cache; |
|
| print "OK\n" |
|
| } |
|
| else { |
|
| print "failed: bad structure; ... removing\n"; |
|
| unlink $file; |
|
| } |
|
| } |
|
| else { |
|
| print STDERR "Can't open cache file '$file': $!"; |
|
| } |
} |
| } |
} |
| } # }}} |
} # }}} |
| Line 208 foreach my $xdir (@directories) { # {{{ |
|
| Line 193 foreach my $xdir (@directories) { # {{{ |
|
| print "Saving cache file '$file' ... "; |
print "Saving cache file '$file' ... "; |
| if (open(FILE, ">$file")) { |
if (open(FILE, ">$file")) { |
| #print Data::Dumper->Dump([$cache->{$xdir}], ['$hardlink_cache']); |
#print Data::Dumper->Dump([$cache->{$xdir}], ['$hardlink_cache']); |
| print FILE Data::Dumper->Dump([$cache->{$xdir}], ['$hardlink_cache']); |
# OLD INSECURE FORMAT OF CACHE |
| |
#print FILE Data::Dumper->Dump([$cache->{$xdir}], ['$hardlink_cache']); |
| |
# more safer new format: |
| |
print FILE $dump->pl2xml($cache->{$xdir}); |
| close(FILE); |
close(FILE); |
| print "OK\n"; |
print "OK\n"; |
| } |
} |