X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=dupemerge;a=blobdiff_plain;f=dm6;h=874534fac260f177fd174250296d0a872fb16aa3;hp=b0ff96b84b633c717bf0516038f74e6ae2be494d;hb=79c8d21ca871e2f52d8de960cbf2534ba4509491;hpb=a888bfab4a7685b300dbf8da06069dd3d2d75bf0 diff --git a/dm6 b/dm6 index b0ff96b..874534f 100755 --- a/dm6 +++ b/dm6 @@ -156,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) { @@ -165,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__