diff options
author | Daniel Friesel <derf@derf.homelinux.org> | 2008-07-11 17:32:59 +0200 |
---|---|---|
committer | Daniel Friesel <derf@derf.homelinux.org> | 2008-07-11 17:32:59 +0200 |
commit | 27e2a2a03ccfe4bed579f83b72d472f3e0c11357 (patch) | |
tree | 66bc9db3422237f48d4033333e41181ef5b59fe8 /bin/checklinks | |
parent | ab2ca24afcc319b62eb2845099633cc7205efb0d (diff) |
Remove every symlink when removing a package
Diffstat (limited to 'bin/checklinks')
-rwxr-xr-x | bin/checklinks | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/bin/checklinks b/bin/checklinks index 1342862..fc67f3b 100755 --- a/bin/checklinks +++ b/bin/checklinks @@ -6,20 +6,29 @@ use Term::ANSIColor; my $base = $ENV{HOME}; my ($type, $src, $dst); my $quiet = 0; +my $remove = 0; unless (-f ".links") { exit 0; } -if (defined($ARGV[0]) and $ARGV[0] eq '-q') { - $quiet = 1; +if (defined($ARGV[0])) { + if ($ARGV[0] eq '-q') { + $quiet = 1; + } + if ($ARGV[0] eq '-r') { + $remove = 1; + } } open(LINKS, '<.links') or die($!); while(<LINKS>) { chomp; ($type, $src, $dst) = split; - if ($type eq 'soft') { + next unless ($type eq 'soft' or $type eq 'hard'); + if ($remove) { + remove_link($src); + } elsif ($type eq 'soft') { check_symlink($src, $dst); } elsif ($type eq 'hard') { check_hardlink($src, $dst); @@ -27,6 +36,15 @@ 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'); + } +} + sub check_symlink { my $src = shift; my $dst = shift; @@ -39,10 +57,10 @@ sub check_symlink { print_format('created', $src, $dst, 'cyan'); } elsif (readlink("$base/$src") eq $dst) { - print_format('ok', $src, $dst, 'green') unless ($quiet); + print_format('ok', $src, $dst, 'green') unless $quiet; } elsif (readlink("$base/$src") eq "$base/$dst") { - print_format('absolute', $src, $dst, 'yellow') unless ($quiet); + print_format('absolute', $src, $dst, 'yellow') unless $quiet; } elsif (not -l "$base/$src" and -e "$base/$src") { print colored ("$base/$src: File exists but is not a symlink. Not updating.\n", 'bold red'); @@ -71,7 +89,7 @@ sub check_hardlink { print_format('updated', $src, $dst, 'cyan'); } elsif ((stat("$base/$src"))[1] == (stat("$base/$dst"))[1]) { - print_format('ok', $src, $dst, 'green') unless ($quiet); + print_format('ok', $src, $dst, 'green') unless $quiet; } } |