X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=dupemerge;a=blobdiff_plain;f=dm6;h=874534fac260f177fd174250296d0a872fb16aa3;hp=a5d56a6545a59258d2742e7dcfcedd0a4be5d843;hb=79c8d21ca871e2f52d8de960cbf2534ba4509491;hpb=790ad0c146598175d7cca5f0c711ec217e196369 diff --git a/dm6 b/dm6 index a5d56a6..874534f 100755 --- a/dm6 +++ b/dm6 @@ -69,10 +69,13 @@ sub link_files { my $link_dir = shift @ARGV; (-d $link_dir) or usage; +my $prefix_length = 3; + sub slash_prefix { my ($file) = @_; - my $prefix = substr($file, 0, 3); - my $suffix = substr($file, 3); + $file .= '_' x (length($file) + 1 - $prefix_length) if length($file) + 1 < $prefix_length; + my $prefix = substr($file, 0, $prefix_length); + my $suffix = substr($file, $prefix_length); $prefix =~ s:(.):$1/:osg; chop($prefix); return ($prefix, $suffix); @@ -153,6 +156,10 @@ while () { undef $digest_st; } } + print STDERR "\b"; + + # Which file are we keeping? + my $keep_file; # If digest link exists, link it to file if ($digest_st) { @@ -162,20 +169,32 @@ while () { # Old, replace input with old file print STDERR '-'; link_files($digest_link, $file); + $keep_file = $digest_link; } else { # New, add input to digest print STDERR '+'; link_files($file, $digest_link); + $keep_file = $file; } # A link to the inode indicates we are done, so do it last - link_files($file, $inode_link); + print STDERR '_'; + link_files($keep_file, $inode_link); } }; warn "$file: $@" if $@; } +# Garbage collection +print STDERR "\nGarbage collection in '$link_dir'..."; +chdir($link_dir) || die "chdir: $link_dir: $!"; +print STDERR "\nRemoving files with link count < 3..."; +system("find digest inode -type f -links -3 -print0 | xargs -0 rm -f") and die "system: exit status $?"; +print STDERR "\nRemoving empty directories..."; +system("find digest inode -type d -empty -print0 | xargs -0r rmdir -p --ignore-fail-on-non-empty") and die "system: exit status $?"; +print STDERR "\nDone.\n"; + exit(0); __END__