From 58d1c669e58dce4f1cb8314d819077e61d66ad48 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 28 Jun 2021 13:24:15 +0000 Subject: [PATCH] kiss: remove broken directory symlinks This changes pkg_remove_files to queue all directory symlinks for removal *after* all other items. Links are only removed if they are broken and a safeguard has been added for root level directories. Also fixed are some bugs around how the paths are stored internally. 1. If KISS_ROOT is empty, path ends up being //path/to/file. 2. Directory symlinks are undetectable when they have '/' as a suffix. --- kiss | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/kiss b/kiss index a231ec7..39b1504 100755 --- a/kiss +++ b/kiss @@ -1073,21 +1073,28 @@ pkg_remove_files() { } esac 2>/dev/null ||: - file=$KISS_ROOT/$file + _file=${KISS_ROOT:+"$KISS_ROOT/"}${file%%/} - # Remove files. - if [ -f "$file" ] && [ ! -h "$file" ]; then - rm -f "$file" + # Queue all directory symlinks for later removal. + if [ -h "$_file" ] && [ -d "$_file" ]; then + case $file in /*/*/) + set -- "$@" "$_file" + esac - # Remove file symlinks. - elif [ -h "$file" ] && [ ! -d "$file" ]; then - rm -f "$file" + # Remove empty directories. + elif [ -d "$_file" ]; then + rmdir "$_file" 2>/dev/null ||: - # Remove directories if empty. - elif [ -d "$file" ] && [ ! -h "$file" ]; then - rmdir "$file" 2>/dev/null ||: + # Remove everything else. + else + rm -f "$_file" fi done ||: + + # Remove all broken directory symlinks. + for sym do + [ -e "$sym" ] || rm -f "$sym" + done } pkg_etc() (