kiss: Fix issues with naming conflicts in source extraction

This commit is contained in:
Dylan Araps 2020-05-09 00:42:39 +03:00
parent 5bbc7f9945
commit ca705d8911
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E

17
kiss
View File

@ -401,23 +401,30 @@ pkg_extract() {
"$tar" xf .ktar || "$tar" xf .ktar ||
die "$1" "Couldn't extract ${src##*/}" die "$1" "Couldn't extract ${src##*/}"
"$tar" tf .ktar | while read -r dir; do dir=${dir%/*} "$tar" tf .ktar | while IFS=/ read -r dir _; do
# Some tarballs contain './' as the top-level directory, # Some tarballs contain './' as the top-level directory,
# we need to skip these occurances. # we need to skip these occurances.
[ -d "${dir#.}" ] || continue [ -d "${dir#.}" ] || continue
# Move the directory to prevent naming conflicts between
# the child and parent
mv -f "$dir" "$$-$dir"
# First attempt to move all files up a directory level, # First attempt to move all files up a directory level,
# if any files/directories fail (due to mv's lack of # if any files/directories fail (due to mv's lack of
# directory merge capability), simply do the exercise # directory merge capability), simply do the exercise
# again and copy-merge the remaining files/directories. # again and copy-merge the remaining files/directories.
find "$dir/." ! -name . -prune -exec mv -f {} . + || {
find "$dir/." ! -name . -prune -exec cp -fRp {} . + find "$$-$dir/." ! -name . -prune -exec mv -f {} . + ||
find "$$-$dir/." ! -name . -prune -exec cp -fRp {} . +
} 2>/dev/null
# Remove the directory now that all files have been # Remove the directory now that all files have been
# transferred out of it. This can't be a simple 'rmdir' # transferred out of it. This can't be a simple 'rmdir'
# as we may leave files in here due to above. # as we may leave files in here due to above.
rm -rf "$dir" rm -rf "$$-$dir"
done 2>/dev/null done
# Clean up after ourselves and remove the temporary tar # Clean up after ourselves and remove the temporary tar
# archive we've created. Not needed at all really. # archive we've created. Not needed at all really.