summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/checklinks30
-rwxr-xr-xbin/pkg1
2 files changed, 25 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;
}
}
diff --git a/bin/pkg b/bin/pkg
index b0fd3c2..870065a 100755
--- a/bin/pkg
+++ b/bin/pkg
@@ -373,6 +373,7 @@ pkg_remove () {
}
exec_hook $1 "pre-remove"
genocide_collected $1
+ checklinks -r
list_remove_package $1
rm -rf $PDIR/$1
info "Package removed.\n"