From e45152d8c98a2fcb80c5b69abe97c440291bd789 Mon Sep 17 00:00:00 2001
From: Daniel Friesel <derf@derf.homelinux.org>
Date: Sat, 12 Sep 2009 00:48:02 +0200
Subject: {populate → update}_collected: Remove broken package symlinks in
 ~/bin
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 bin/ct            | 13 ++++++++++---
 include/bootstrap |  2 +-
 test/add          |  2 +-
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/bin/ct b/bin/ct
index 6582398..0bf6cb4 100755
--- a/bin/ct
+++ b/bin/ct
@@ -422,7 +422,7 @@ function global_hook {
 			checklinks $CL_OPTIONS \
 				--parameter package=${${PWD#$HOME}#/##} \
 				--parameter etc=${${PWD#$HOME}#/##}/etc
-			populate_collected $1
+			update_collected $1
 			update_provides $1
 			list_package_update $1
 		;;
@@ -528,7 +528,7 @@ function check_prereqs {
 
 # Write a package's documentation to .collected
 # and symlink its binaries from ~/bin
-function populate_collected {
+function update_collected {
 	cd $PKG_DIR/$1 || return
 	typeset -i bins=0 bino=0 mans=0 mano=0
 	typeset man section manpage file target
@@ -553,6 +553,13 @@ function populate_collected {
 			pod2man -u $file > $PKG_DIR/.collected/man/man1/${file:t}.1
 		fi
 	}
+	for file in ~/bin/*(@N); {
+		if [[ $(readlink $file) == (../${PKG_DIR//$HOME\/}|$PKG_DIR)/$1/bin/${file:t} ]] {
+			if [[ ! -e $PKG_DIR/$1/bin/${file:t} ]] {
+				rm $file
+			}
+		}
+	}
 	for file in bin/*(-*N); {
 		if [[ -L $HOME/$file || ! -e $HOME/$file ]] {
 			if [[ $(readlink $HOME/$file) != (../${PKG_DIR//$HOME\/}|$PKG_DIR)/$1/$file ]] {
@@ -564,7 +571,7 @@ function populate_collected {
 				}
 			}
 		} else {
-			warn "populate_collected: ~/$file is not a symlink - skipping $1/$file\n" \
+			warn "update_collected: ~/$file is not a symlink - skipping $1/$file\n" \
 			     "Please fix manually and then call '$0 refresh $1'\n"
 		}
 	}
diff --git a/include/bootstrap b/include/bootstrap
index 9befef0..09820fa 100755
--- a/include/bootstrap
+++ b/include/bootstrap
@@ -95,7 +95,7 @@ if ((pkglist_cgi)) {
 echo 'Installing caretaker package'
 rehash
 bin/checklinks
-bin/ct eval populate_collected caretaker
+bin/ct eval update_collected caretaker
 bin/ct eval exec_hook caretaker post-add
 
 bin/ct update
diff --git a/test/add b/test/add
index 8094c2b..7d63439 100644
--- a/test/add
+++ b/test/add
@@ -7,7 +7,7 @@ ct add $repo
 echo "# ct add (already installed)"
 ! ct add $repo
 
-echo "# populate_collected"
+echo "# update_collected"
 [[ -L $test_home/bin/$file ]]
 [[ -x $(readlink $test_home/bin/$file) ]]
 [[ -e $test_pdir/.collected/man/man2/$file.2 ]]
-- 
cgit v1.2.3