kiss: remove pipe/pointless check from tar extraction

- Directory check was in reality a NULL check. ie, '' is not a
  directory. Changed to use case.

- Removed pipe when iterating over tarball manifest. Swapped to
  using a temporaru file to avoid subshell.
This commit is contained in:
Dylan Araps 2021-07-16 20:34:47 +03:00
parent 7a9fde9494
commit bf2e18c5d8
No known key found for this signature in database
GPG Key ID: 13295DAC2CF13B5C

35
kiss
View File

@ -381,38 +381,33 @@ pkg_extract_tar_hack() {
# '--strip-components 1'. Use of this function denotes a # '--strip-components 1'. Use of this function denotes a
# performance penalty. # performance penalty.
tmp_file "$1" tarball tmp_file "$1" tarball
tmp_file "$1" tarball-manifest
decompress "$2" > "$_tmp_file" || decompress "$2" > "$_tmp_file_pre" ||
die "$1" "Failed to decompress $2" die "$1" "Failed to decompress $2"
tar xf "$_tmp_file" || tar xf "$_tmp_file_pre" ||
die "$1" "Failed to extract $2" die "$1" "Failed to extract $2"
tar tf "$_tmp_file_pre" > "$_tmp_file" ||
die "$1" "Failed to extract manifest"
# Iterate over all directories in the first level of the # Iterate over all directories in the first level of the
# tarball's manifest. # tarball's manifest. Each directory is moved up a level.
tar tf "$_tmp_file" | while IFS=/ read -r dir _; do while IFS=/ read -r dir _; do case ${dir#.} in *?*)
# Skip the directory if seen before. # Skip duplicate directories.
! contains "$_seen" "$dir" || continue && _seen="$_seen $dir" ! contains "$_seen" "$dir" || continue && _seen="$_seen $dir"
# Some tarballs contain './' as the top-level directory, # Move the parent directory to prevent naming conflicts
# we need to skip these occurances. # with the to-be-moved children.
[ -d "${dir#.}" ] || continue
# Move the directory to prevent naming conflicts between
# the child and parent.
mv -f "$dir" "$KISS_PID-$dir" mv -f "$dir" "$KISS_PID-$dir"
# First attempt to move all files up a directory level, # Move all children up a directory level. If the mv command
# if any files/directories fail (due to mv's lack of # fails, fallback to copying the remainder of the files.
# directory merge capability), simply do the exercise
# again and copy-merge the remaining files/directories.
# #
# We can't use '-exec {} +' with any arguments between # We can't use '-exec {} +' with any arguments between
# the '{}' and '+' as this is not POSIX. We must also # the '{}' and '+' as this is not POSIX. We must also
# use '$0' and '$@' to reference all arguments. # use '$0' and '$@' to reference all arguments.
#
# Using only '$@' causes a single file from each
# invocation to be left out of the list. Weird, right?
find "$KISS_PID-$dir/." ! -name . -prune \ find "$KISS_PID-$dir/." ! -name . -prune \
-exec sh -c 'mv -f "$0" "$@" .' {} + 2>/dev/null || -exec sh -c 'mv -f "$0" "$@" .' {} + 2>/dev/null ||
@ -423,10 +418,10 @@ pkg_extract_tar_hack() {
# 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 if any were copied. # as we may leave files in here if any were copied.
rm -rf "$KISS_PID-$dir" rm -rf "$KISS_PID-$dir"
done esac done < "$_tmp_file"
# Remove the tarball now that we are done with it. # Remove the tarball now that we are done with it.
rm -f "$_tmp_file" rm -f "$_tmp_file_pre"
} }
pkg_extract() { pkg_extract() {