]> Sergey Matveev's repositories - zsh-autoenv.git/commitdiff
Encapsulate the file name in the hash pair for stricter matching
authorDaniel Hahler <git@thequod.de>
Thu, 4 Dec 2014 09:35:09 +0000 (10:35 +0100)
committerDaniel Hahler <git@thequod.de>
Thu, 4 Dec 2014 09:35:09 +0000 (10:35 +0100)
Ref: https://github.com/Tarrasch/zsh-autoenv/pull/13#issuecomment-65559752

autoenv.zsh
tests/_autoenv_utils.t

index 14e8159432c6e285225342ddd65f880f04ae4ee1..0cc056684187d932f39ddd42729fe2ce13d647f4 100644 (file)
@@ -136,7 +136,7 @@ _autoenv_hash_pair() {
     fi
     env_shasum=$(shasum $env_file | cut -d' ' -f1)
   fi
-  echo "$env_file:$env_shasum:1"
+  echo ":${env_file}:${env_shasum}:1"
 }
 
 _autoenv_authorized_env_file() {
@@ -147,15 +147,15 @@ _autoenv_authorized_env_file() {
 }
 
 _autoenv_authorize() {
-  local env_file=$1
+  local env_file=${1:A}
   _autoenv_deauthorize $env_file
   _autoenv_hash_pair $env_file >> $AUTOENV_ENV_FILENAME
 }
 
 _autoenv_deauthorize() {
-  local env_file=$1
+  local env_file=${1:A}
   if [[ -s $AUTOENV_ENV_FILENAME ]]; then
-    echo "$(\grep -vF $env_file $AUTOENV_ENV_FILENAME)" > $AUTOENV_ENV_FILENAME
+    echo "$(\grep -vF :${env_file}: $AUTOENV_ENV_FILENAME)" > $AUTOENV_ENV_FILENAME
   fi
 }
 
index c8c4a8c4e5ff3170cdf1090d83869f297b7612ba..3da1fde11ff22fa30ce4f3a9d74da42c674dc855 100644 (file)
@@ -35,39 +35,39 @@ Now adding some auth pair.
   $ echo first > first
   $ _autoenv_authorize first
   $ cat $AUTOENV_ENV_FILENAME
-  /tmp/cramtests-*/_autoenv_utils.t/first:271ac93c44ac198d92e706c6d6f1d84aefcfa337:1 (glob)
+  :/tmp/cramtests-*/_autoenv_utils.t/first:271ac93c44ac198d92e706c6d6f1d84aefcfa337:1 (glob)
 
 And a second one.
 
   $ echo second > second
   $ _autoenv_authorize second
   $ cat $AUTOENV_ENV_FILENAME
-  /tmp/cramtests-*/_autoenv_utils.t/first:271ac93c44ac198d92e706c6d6f1d84aefcfa337:1 (glob)
-  /tmp/cramtests-*/_autoenv_utils.t/second:7bee8f3b184e1e141ff76efe369c3b8bfc50e64c:1 (glob)
+  :/tmp/cramtests-*/_autoenv_utils.t/first:271ac93c44ac198d92e706c6d6f1d84aefcfa337:1 (glob)
+  :/tmp/cramtests-*/_autoenv_utils.t/second:7bee8f3b184e1e141ff76efe369c3b8bfc50e64c:1 (glob)
 
 And a third.
 
   $ echo third > third
   $ _autoenv_authorize third
   $ cat $AUTOENV_ENV_FILENAME
-  /tmp/cramtests-*/_autoenv_utils.t/first:271ac93c44ac198d92e706c6d6f1d84aefcfa337:1 (glob)
-  /tmp/cramtests-*/_autoenv_utils.t/second:7bee8f3b184e1e141ff76efe369c3b8bfc50e64c:1 (glob)
-  /tmp/cramtests-*/_autoenv_utils.t/third:ad180453bf8a374a15df3e90a78c180230146a7c:1 (glob)
+  :/tmp/cramtests-*/_autoenv_utils.t/first:271ac93c44ac198d92e706c6d6f1d84aefcfa337:1 (glob)
+  :/tmp/cramtests-*/_autoenv_utils.t/second:7bee8f3b184e1e141ff76efe369c3b8bfc50e64c:1 (glob)
+  :/tmp/cramtests-*/_autoenv_utils.t/third:ad180453bf8a374a15df3e90a78c180230146a7c:1 (glob)
 
 Re-add the second one, with the same hash.
 
   $ _autoenv_authorize second
   $ cat $AUTOENV_ENV_FILENAME
-  /tmp/cramtests-*/_autoenv_utils.t/first:271ac93c44ac198d92e706c6d6f1d84aefcfa337:1 (glob)
-  /tmp/cramtests-*/_autoenv_utils.t/third:ad180453bf8a374a15df3e90a78c180230146a7c:1 (glob)
-  /tmp/cramtests-*/_autoenv_utils.t/second:7bee8f3b184e1e141ff76efe369c3b8bfc50e64c:1 (glob)
+  :/tmp/cramtests-*/_autoenv_utils.t/first:271ac93c44ac198d92e706c6d6f1d84aefcfa337:1 (glob)
+  :/tmp/cramtests-*/_autoenv_utils.t/third:ad180453bf8a374a15df3e90a78c180230146a7c:1 (glob)
+  :/tmp/cramtests-*/_autoenv_utils.t/second:7bee8f3b184e1e141ff76efe369c3b8bfc50e64c:1 (glob)
 
 Re-add the first one, with a new hash.
 
   $ echo one more line >> first
   $ _autoenv_authorize first
   $ cat $AUTOENV_ENV_FILENAME
-  /tmp/cramtests-*/_autoenv_utils.t/third:ad180453bf8a374a15df3e90a78c180230146a7c:1 (glob)
-  /tmp/cramtests-*/_autoenv_utils.t/second:7bee8f3b184e1e141ff76efe369c3b8bfc50e64c:1 (glob)
-  /tmp/cramtests-*/_autoenv_utils.t/first:65eb010197b73ddc109b7210080f97a87f53451e:1 (glob)
+  :/tmp/cramtests-*/_autoenv_utils.t/third:ad180453bf8a374a15df3e90a78c180230146a7c:1 (glob)
+  :/tmp/cramtests-*/_autoenv_utils.t/second:7bee8f3b184e1e141ff76efe369c3b8bfc50e64c:1 (glob)
+  :/tmp/cramtests-*/_autoenv_utils.t/first:65eb010197b73ddc109b7210080f97a87f53451e:1 (glob)
 }}}