From d45d6205de2e41b99405efae1066d36dcff71fbd Mon Sep 17 00:00:00 2001 From: Lily Ballard Date: Mon, 5 Aug 2019 21:27:21 -0700 Subject: [PATCH] setup.sh: rewrite stripHash Rewrite the `stripHash` helper function with 2 differences: * Paths starting with `--` will no longer produce an error. * Use Bash string manipulation instead of shelling out to `grep` and `cut`. This should be faster. --- pkgs/stdenv/generic/setup.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 730e77c20f9..5b8fdde5796 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -787,14 +787,17 @@ dumpVars() { # Utility function: echo the base name of the given path, with the # prefix `HASH-' removed, if present. stripHash() { - local strippedName + local strippedName casematchOpt=0 # On separate line for `set -e` - strippedName="$(basename "$1")" - if echo "$strippedName" | grep -q '^[a-z0-9]\{32\}-'; then - echo "$strippedName" | cut -c34- + strippedName="$(basename -- "$1")" + shopt -q nocasematch && casematchOpt=1 + shopt -u nocasematch + if [[ "$strippedName" =~ ^[a-z0-9]{32}- ]]; then + echo "${strippedName:33}" else echo "$strippedName" fi + if (( casematchOpt )); then shopt -s nocasematch; fi }