From 63ab42206f25e181f626ec0c7ddad045fa27846c Mon Sep 17 00:00:00 2001 From: Mike Burns Date: Sun, 11 Aug 2013 15:38:06 +0200 Subject: rcdn only removes symlinks Picture this case: % ls -l ~/.a ~/.a -> ~/.dotfiles/a % tree ~/.dotfiles/a a `-- b `-- c `-- d `-- foo Ideally we would want `~/.a/b/c/d/foo` to be the symlink, and the rest to be actual directories. However, some people did it differently. Running `rcdn` on the above would previously have removed `foo` from `~/.dotfiles`. Now, it removes `~/.a` and nothing more. --- bin/rcdn | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'bin/rcdn') diff --git a/bin/rcdn b/bin/rcdn index a7fb81d..99812aa 100755 --- a/bin/rcdn +++ b/bin/rcdn @@ -3,6 +3,20 @@ : ${RCM_LIB:=`dirname $0`/../share/rcm} . $RCM_LIB/rcm.sh +remove_link() { + local dest=$1 + local original=$2 + + if [ x$dest = "x/" ]; then + $VERBOSE "not a symlink, skipping: $original" + elif [ -L $dest ]; then + $RM -rf $dest + rmdir -p `dirname $original` 2>/dev/null + else + remove_link `dirname $dest` $original + fi +} + handle_command_line() { local arg_tags= local verbosity=0 @@ -58,6 +72,5 @@ for dest_and_src in `lsrc $LS_ARGS`; do dest=`echo $dest_and_src | sed 's/:.*//'` src=`echo $dest_and_src | sed 's/.*://'` - $RM -rf $dest - rmdir -p `dirname $dest` 2>/dev/null + remove_link $dest $dest done -- cgit v1.2.3