]> Sergey Matveev's repositories - zsh-autoenv.git/commitdiff
_autoenv_get_file_upwards: do not dereference symlinks (#73)
authorRob Speed <speed.rob@gmail.com>
Thu, 2 Nov 2017 01:40:45 +0000 (21:40 -0400)
committerDaniel Hahler <github@thequod.de>
Thu, 2 Nov 2017 01:40:45 +0000 (02:40 +0100)
This prevents issues where autoenv scripts use $0. When a shell enters the directory holding the autoenv scripts, it works as expected with $0 being the path to the symlink. However, if the shell enters one of its child directories the path to the script is dereferenced, and $0 is instead the path to the symlink's target.

From `man 1 zshexpn`:

> A – Turn a file name into an absolute path as the 'a' modifier does, and then pass  the  result  through  the  realpath(3) library function to resolve symbolic links.

Note: Symlinks are dereferenced elsewhere for authorization, so that behavior is unchanged.

autoenv.zsh
tests/_autoenv_utils.t

index 4ccc9ae8076de04dac7ea60b2d62d78dd352447b..2deac546596dda7728b1934d1602bcf39ffbbd5d 100644 (file)
@@ -339,7 +339,7 @@ _autoenv_get_file_upwards() {
       if [[ ${parent_file[1,2]} == './' ]]; then
         echo ${parent_file#./}
       else
-        echo ${parent_file:A}
+        echo ${parent_file:a}
       fi
       break
     fi
index a23f18990528157f63306dbd574b2723b74c64ef..c77779f969a6cf108b20ac4988323b424a181199 100644 (file)
@@ -17,6 +17,15 @@ Should not get the file from the current dir.
   $ _autoenv_get_file_upwards $PWD file
   */_autoenv_utils.t/sub/file (glob)
 
+_autoenv_get_file_upwards should not dereference symlinks.
+
+  $ cd ../..
+  $ ln -s sub symlink
+  $ cd symlink/sub2
+  $ _autoenv_get_file_upwards . file
+  ../file
+  $ _autoenv_get_file_upwards $PWD file
+  */_autoenv_utils.t/symlink/file (glob)
 
 Tests for _autoenv_authorize. {{{