diff options
author | Daniel Friesel <derf@derf.homelinux.org> | 2009-07-16 16:45:10 +0200 |
---|---|---|
committer | Daniel Friesel <derf@derf.homelinux.org> | 2009-07-16 16:45:10 +0200 |
commit | 00ef8525200cd887f206ebdaf973058ee4581742 (patch) | |
tree | cd2c493125d7b229d3fa6edea0213d0c3cc2559f /bin/checklinks | |
parent | 81c0fa5c3b74568b8f3ccf57f214ccbfc52ae20b (diff) |
checklinks: --remove: unlink hardlink sources as well
Diffstat (limited to 'bin/checklinks')
-rwxr-xr-x | bin/checklinks | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/bin/checklinks b/bin/checklinks index 0a3337a..0e20186 100755 --- a/bin/checklinks +++ b/bin/checklinks @@ -37,7 +37,7 @@ while(<$links>) { my ($type, $src, $dst) = split; next unless ($type eq 'soft' or $type eq 'hard'); if ($remove) { - remove_link($src); + remove_link($type, $src, $dst); } elsif ($type eq 'soft') { check_symlink($src, $dst); } elsif ($type eq 'hard') { @@ -47,11 +47,14 @@ while(<$links>) { close($links); sub remove_link { - my $link = shift; - - if (-l "$base/$link") { - unlink("$base/$link") or warn("cannot unlink $base/$link: $!"); - print_format('removed', $link, '', 'red', 1); + my ($type, $src, $dst) = @_; + + if ( + ($type eq 'soft' and -l "$base/$src") + or ($type eq 'hard' and -e "$base/$src" and -e "$base/$dst") + ) { + unlink("$base/$src") or warn("cannot unlink $base/$src: $!"); + print_format('removed', $src, '', 'red', 1); } return; } @@ -178,7 +181,7 @@ Shortcut for C<< --msglevel=1 >> =item B<-r>, B<--remove> -Remove all symlinks. Hardlinks will be left as they are. +Remove all link sources (hardlinks: only if their destination exists) =back |