From 9159b9577f51f60f13f34506280737be0b4edd97 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 26 Feb 2021 17:25:14 +0300 Subject: Convert bash functions that return arrays to comply with Bash Style Guide --- brep/handler/ci/ci-load.in | 11 ++++------- brep/handler/submit/submit-git.bash.in | 3 +-- brep/handler/submit/submit-git.in | 9 +++++---- brep/handler/submit/submit-pub.in | 10 ++++++---- 4 files changed, 16 insertions(+), 17 deletions(-) (limited to 'brep/handler') diff --git a/brep/handler/ci/ci-load.in b/brep/handler/ci/ci-load.in index f62bb76..cd2b879 100644 --- a/brep/handler/ci/ci-load.in +++ b/brep/handler/ci/ci-load.in @@ -213,28 +213,25 @@ while [ "$more" ]; do manifest_names+=("$n") manifest_values+=("$v") - done # Reduce the first manifest case. # - if [ ${#manifest_names[@]} -eq 0 ]; then + if [[ "${#manifest_names[@]}" -eq 0 ]]; then continue fi # Add or filter out the manifest, if present. # - if [ ${#packages[@]} -ne 0 ]; then - - if [[ -v packages["$name"] ]]; then + if [[ "${#packages[@]}" -ne 0 ]]; then + if [[ -v "packages[$name]" ]]; then packages["$name"]= packages["$name/$version"]= # Clear it either, as may also be present. - elif [[ -v packages["$name/$version"] ]]; then + elif [[ -v "packages[$name/$version]" ]]; then packages["$name/$version"]= else continue # Skip. fi - fi packages_manifest_names+=("${manifest_names[@]}") diff --git a/brep/handler/submit/submit-git.bash.in b/brep/handler/submit/submit-git.bash.in index cc679c8..4b30bc0 100644 --- a/brep/handler/submit/submit-git.bash.in +++ b/brep/handler/submit/submit-git.bash.in @@ -78,8 +78,7 @@ function check_package_duplicate () # local s for s in "${!sections[@]}"; do local p - IFS=$'\n' eval \ - 'p=($(run pkg_find_archive "$nam-$ver.*" "$rep/${sections[$s]}"))' + run pkg_find_archive "$nam-$ver.*" "$rep/${sections[$s]}" | readarray -t p if [ "${#p[@]}" -ne 0 ]; then local n="${p[1]}" diff --git a/brep/handler/submit/submit-git.in b/brep/handler/submit/submit-git.in index c67c30c..8bf6a07 100644 --- a/brep/handler/submit/submit-git.in +++ b/brep/handler/submit/submit-git.in @@ -186,8 +186,10 @@ git_timeout=10 ref_lock_timeout=30 trap "{ exit 1; }" ERR -set -o errtrace # Trap ERR in functions. -set -o pipefail # Return the rightmost non-zero exit status in a pipeline. +set -o errtrace # Trap in functions and subshells. +set -o pipefail # Fail if any pipeline command fails. +shopt -s lastpipe # Execute last pipeline command in the current shell. +shopt -s nullglob # Expand no-match globs to nothing rather than themselves. @import brep/handler/handler@ @import brep/handler/submit/submit@ @@ -639,8 +641,7 @@ for i in {1..11}; do exit_with_manifest 400 "unrecognized section '$section'" fi - IFS=$'\n' eval \ - 'arcs=($(run pkg_find_archives "$name" "$version*" "$tgt_dir/$s"))' + run pkg_find_archives "$name" "$version*" "$tgt_dir/$s" | readarray -t arcs for f in "${arcs[@]}"; do run git -C "$tgt_dir" rm $gqo "${f#$tgt_dir/}" >&2 diff --git a/brep/handler/submit/submit-pub.in b/brep/handler/submit/submit-pub.in index ccb701d..ea12a29 100644 --- a/brep/handler/submit/submit-pub.in +++ b/brep/handler/submit/submit-pub.in @@ -85,7 +85,10 @@ verbose= #true rep_lock_timeout=60 trap "{ exit 1; }" ERR -set -o errtrace # Trap ERR in functions. +set -o errtrace # Trap in functions and subshells. +set -o pipefail # Fail if any pipeline command fails. +shopt -s lastpipe # Execute last pipeline command in the current shell. +shopt -s nullglob # Expand no-match globs to nothing rather than themselves. @import brep/handler/handler@ @import brep/handler/submit/submit@ @@ -297,7 +300,7 @@ trap exit_trap EXIT # Use -.* without .tar.gz in case we want to support more # archive types later. # -IFS=$'\n' eval 'p=($(run pkg_find_archive "$name-$version.*" "$repo_old/1"))' +run pkg_find_archive "$name-$version.*" "$repo_old/1" | readarray -t p if [ "${#p[@]}" -ne 0 ]; then n="${p[1]}" @@ -327,8 +330,7 @@ run rsync -rtO --exclude 'packages.manifest' --link-dest="$repo_old" \ # Remove the package version revision archives that may exist in the # repository. # -IFS=$'\n' eval \ -'arcs=($(run pkg_find_archives "$name" "$version*" "$repo_new/1"))' +run pkg_find_archives "$name" "$version*" "$repo_new/1" | readarray -t arcs for f in "${arcs[@]}"; do run rm "$f" -- cgit v1.1