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.
This commit is contained in:
Dylan Araps 2021-06-28 13:24:15 +00:00
parent 104ace0522
commit 58d1c669e5
1 changed files with 17 additions and 10 deletions

27
kiss
View File

@ -1073,21 +1073,28 @@ pkg_remove_files() {
} }
esac 2>/dev/null ||: esac 2>/dev/null ||:
file=$KISS_ROOT/$file _file=${KISS_ROOT:+"$KISS_ROOT/"}${file%%/}
# Remove files. # Queue all directory symlinks for later removal.
if [ -f "$file" ] && [ ! -h "$file" ]; then if [ -h "$_file" ] && [ -d "$_file" ]; then
rm -f "$file" case $file in /*/*/)
set -- "$@" "$_file"
esac
# Remove file symlinks. # Remove empty directories.
elif [ -h "$file" ] && [ ! -d "$file" ]; then elif [ -d "$_file" ]; then
rm -f "$file" rmdir "$_file" 2>/dev/null ||:
# Remove directories if empty. # Remove everything else.
elif [ -d "$file" ] && [ ! -h "$file" ]; then else
rmdir "$file" 2>/dev/null ||: rm -f "$_file"
fi fi
done ||: done ||:
# Remove all broken directory symlinks.
for sym do
[ -e "$sym" ] || rm -f "$sym"
done
} }
pkg_etc() ( pkg_etc() (