From 0c7657bf0bd41f741802ae8e8dedbaac867b671e Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Fri, 7 Oct 2016 20:02:24 +0300 Subject: update_checksums: don't recalculate existing --- %HOME%/.bash_utils/distr.sh | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/%HOME%/.bash_utils/distr.sh b/%HOME%/.bash_utils/distr.sh index 06d342a..58e088a 100644 --- a/%HOME%/.bash_utils/distr.sh +++ b/%HOME%/.bash_utils/distr.sh @@ -7,9 +7,36 @@ checksums_path='sha1sums.txt' -update_checksums() { - sha1sum -- "$@" > "$checksums_path" -} +list_checksums_paths() ( + set -o errexit -o nounset -o pipefail + + if [ -f "$checksums_path" ]; then + local path + while IFS= read -r path; do + printf "$path"'\0' + done < <( sed --binary 's/^\\\?[[:alnum:]]\+ [ *]//' "$checksums_path" ) + fi +) + +update_checksums() ( + set -o errexit -o nounset -o pipefail + + local path + + local -A existing + while IFS= read -d '' -r path; do + existing[$path]=1 + done < <( list_checksums_paths ) + + local -a missing + for path in "$@"; do + if [ -z "${existing[$path]+x}" ]; then + missing+=("$path") + fi + done + + sha1sum -- "${missing[@]+"${missing[@]}"}" >> "$checksums_path" +) update_checksums_distr() ( set -o errexit -o nounset -o pipefail @@ -19,7 +46,7 @@ update_checksums_distr() ( while IFS= read -d '' -r path; do paths+=("$path") - done < <( find . -type f -\( -iname '*.exe' -o -iname '*.iso' -\) -print0 ) + done < <( find . -type f -\( -iname '*.exe' -o -iname '*.iso' -\) -printf '%P\0' ) update_checksums "${paths[@]+"${paths[@]}"}" ) -- cgit v1.2.3