From fc05246b3b5187039630f87f1251028305e6f34a Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 17 Jul 2021 17:49:43 +0300 Subject: [PATCH] kiss: reduce indentation --- kiss | 92 +++++++++++++++++++++++++++--------------------------------- 1 file changed, 42 insertions(+), 50 deletions(-) diff --git a/kiss b/kiss index 6896a10..f37ff2a 100755 --- a/kiss +++ b/kiss @@ -1149,62 +1149,54 @@ file_rwx() { } pkg_install_files() { - while read -r file; do - _file=$KISS_ROOT$file + # Copy files and create directories (preserving permissions). + while { read -r file && _file=$KISS_ROOT$file; } do case $file in + /etc/*[!/]) + # Handle /etc/ files in a special way (via a 3-way checksum) to + # determine how these files should be installed. Do we overwrite + # the existing file? Do we install it as $file.new to avoid + # deleting user configuration? etc. + # + # This is more or less similar to Arch Linux's Pacman with the + # user manually handling the .new files when and if they appear. + test "$1" "$_file" || pkg_etc "$file" "$_tmp_file_pre_pre" + ;; - # Copy files and create directories (preserving permissions), - # skipping anything located in /etc/. - # - # The 'test' will run with '-e' for no-overwrite and '-z' - # for overwrite. - case $file in - /etc/*[!/]) - # Handle /etc/ files in a special way (via a 3-way checksum) to - # determine how these files should be installed. Do we overwrite - # the existing file? Do we install it as $file.new to avoid - # deleting user configuration? etc. - # - # This is more or less similar to Arch Linux's Pacman with the - # user manually handling the .new files when and if they appear. - test "$1" "$_file" || pkg_etc "$file" "$_tmp_file_pre_pre" - ;; + */) + # Skip directories if they already exist in the file system. + # (Think /usr/bin, /usr/lib, etc). + [ -d "$_file" ] || { + file_rwx "$2/${file#/}" + mkdir -m "$oct" "$_file" + } + ;; - */) - # Skip directories if they already exist in the file system. - # (Think /usr/bin, /usr/lib, etc). - [ -d "$_file" ] || { - file_rwx "$2/${file#/}" - mkdir -m "$oct" "$_file" - } - ;; + *) + if [ -d "$_file" ] || test "$1" "$_file"; then + # Skip directories as they're likely symlinks in this case. + # Pure directories in manifests have a suffix of '/'. + continue - *) - if [ -d "$_file" ] || test "$1" "$_file"; then - # Skip directories as they're likely symlinks in this case. - # Pure directories in manifests have a suffix of '/'. - continue + elif [ -h "$_file" ]; then + # Copy the file to the destination directory overwriting + # any existing file. + cp -fP "$2$file" "${_file%/*}/." - elif [ -h "$_file" ]; then - # Copy the file to the destination directory overwriting - # any existing file. - cp -fP "$2$file" "${_file%/*}/." + else + # Construct a temporary filename which is a) unique and + # b) identifiable as related to the package manager. + __tmp=${_file%/*}/__kiss-tmp-$_pkg-${file##*/}-$KISS_PID - else - # Construct a temporary filename which is a) unique and - # b) identifiable as related to the package manager. - __tmp=${_file%/*}/__kiss-tmp-$_pkg-${file##*/}-$KISS_PID + # Copy the file to the destination directory with the + # temporary name created above. + cp -fP "$2$file" "$__tmp" && - # Copy the file to the destination directory with the - # temporary name created above. - cp -fP "$2$file" "$__tmp" && - - # Atomically move the temporary file to its final - # destination. The running processes will either get - # the old file or the new one. - mv -f "$__tmp" "$_file" - fi - esac || return 1 - done + # Atomically move the temporary file to its final + # destination. The running processes will either get + # the old file or the new one. + mv -f "$__tmp" "$_file" + fi + esac || return 1; done unset _etc_cnt }