]> Sergey Matveev's repositories - zsh-autoenv.git/commitdiff
_autoenv_hash_pair: do not use a subshell (#81)
authorDaniel Hahler <github@thequod.de>
Fri, 15 Dec 2017 14:59:11 +0000 (15:59 +0100)
committerGitHub <noreply@github.com>
Fri, 15 Dec 2017 14:59:11 +0000 (15:59 +0100)
As a side-effect this should fix
https://github.com/Tarrasch/zsh-autoenv/issues/39 in case it was still
an issue after all.

autoenv.zsh
tests/setup.zsh

index 2164bd37135f67a92030d83d2199d98026162e55..538e92fcb1db2c30f469f734729ac654934e9216 100644 (file)
@@ -172,6 +172,7 @@ _autoenv_hash_pair() {
   local env_file=${1:A}
   local cksum_version=${2:-2}
   local env_cksum=${3:-}
+  ret_pair=
   if [[ -z $env_cksum ]]; then
     if ! [[ -e $env_file ]]; then
       echo "Missing file argument for _autoenv_hash_pair!" >&2
@@ -187,7 +188,7 @@ _autoenv_hash_pair() {
       return 1
     fi
   fi
-  echo ":${env_file}:${env_cksum}:${cksum_version}"
+  ret_pair=":${env_file}:${env_cksum}:${cksum_version}"
 }
 
 
@@ -201,14 +202,14 @@ _autoenv_authorized_pair() {
 
 _autoenv_authorized_env_file() {
   local env_file=$1
-  local pair
-  pair=$(_autoenv_hash_pair $env_file)
-  _autoenv_debug "v2 pair: ${pair}"
-  if ! _autoenv_authorized_pair $pair; then
+  local ret_pair
+  _autoenv_hash_pair $env_file
+  _autoenv_debug "v2 pair: ${ret_pair}"
+  if ! _autoenv_authorized_pair $ret_pair; then
     # Fallback for v1 (SHA-1) pairs
-    pair=$(_autoenv_hash_pair $env_file 1)
-    _autoenv_debug "v1 pair: ${pair}"
-    if _autoenv_authorized_pair $pair; then
+    _autoenv_hash_pair $env_file 1
+    _autoenv_debug "v1 pair: ${ret_pair}"
+    if _autoenv_authorized_pair $ret_pair; then
       # Upgrade v1 entries to v2
       _autoenv_authorize $env_file
     else
@@ -221,7 +222,10 @@ _autoenv_authorize() {
   local env_file=${1:A}
   _autoenv_deauthorize $env_file
   [[ -d ${AUTOENV_AUTH_FILE:h} ]] || mkdir -p ${AUTOENV_AUTH_FILE:h}
-  _autoenv_hash_pair $env_file >>| $AUTOENV_AUTH_FILE
+  {
+    local ret_pair
+    _autoenv_hash_pair $env_file && echo "$ret_pair"
+  } >>| $AUTOENV_AUTH_FILE
 }
 
 # Deauthorize a given filename, by removing it from the auth file.
index d1e26ed51e81c627171d3bd47bc4f5ef5546ee01..9b24765ea61452f171d51fae7bf17272e4110f30 100644 (file)
@@ -26,7 +26,10 @@ fi
 # Add file ($1), version ($2), and optional hash ($3) to authentication file.
 test_autoenv_add_to_env() {
   [[ -d ${AUTOENV_AUTH_FILE:h} ]] || mkdir -p ${AUTOENV_AUTH_FILE:h}
-  _autoenv_hash_pair $1 1 ${2:-} >>| $AUTOENV_AUTH_FILE
+  {
+    local ret_pair
+    _autoenv_hash_pair $1 1 ${2:-} && echo $ret_pair
+  } >>| $AUTOENV_AUTH_FILE
 }
 
 # Add enter and leave env files to authentication file.