mirror of
https://github.com/Tarrasch/zsh-autoenv.git
synced 2024-11-22 15:30:59 +02:00
Fix symlink handling, especially for symlinks not below "env_dir"
This commit is contained in:
parent
392bca542c
commit
873b9f8062
19
autoenv.zsh
19
autoenv.zsh
@ -74,11 +74,24 @@ _autoenv_stack_entered_remove() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Is the given entry already in the stack?
|
# Is the given entry already in the stack?
|
||||||
|
# This checks for the env_file ($1) as-is and with symlinks resolved.
|
||||||
_autoenv_stack_entered_contains() {
|
_autoenv_stack_entered_contains() {
|
||||||
local env_file=$1
|
local env_file=$1
|
||||||
|
local f i
|
||||||
if (( ${+_autoenv_stack_entered[(r)${env_file}]} )); then
|
if (( ${+_autoenv_stack_entered[(r)${env_file}]} )); then
|
||||||
# Entry is in stack.
|
# Entry is in stack.
|
||||||
if [[ $_autoenv_stack_entered_mtime[$env_file] == $(_autoenv_get_file_mtime $env_file) ]]; then
|
f=$env_file
|
||||||
|
else
|
||||||
|
for i in $_autoenv_stack_entered; do
|
||||||
|
if [[ ${i:A} == ${env_file:A} ]]; then
|
||||||
|
# Entry is in stack (compared with resolved symlinks).
|
||||||
|
f=$i
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
if [[ -n $f ]]; then
|
||||||
|
if [[ $_autoenv_stack_entered_mtime[$f] == $(_autoenv_get_file_mtime $f) ]]; then
|
||||||
# Entry has the expected mtime.
|
# Entry has the expected mtime.
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
@ -275,8 +288,8 @@ _autoenv_chpwd_handler() {
|
|||||||
if [[ $AUTOENV_HANDLE_LEAVE == 1 ]] && (( $#_autoenv_stack_entered )); then
|
if [[ $AUTOENV_HANDLE_LEAVE == 1 ]] && (( $#_autoenv_stack_entered )); then
|
||||||
local prev_file prev_dir
|
local prev_file prev_dir
|
||||||
for prev_file in ${_autoenv_stack_entered}; do
|
for prev_file in ${_autoenv_stack_entered}; do
|
||||||
prev_dir=${prev_file:A:h}
|
prev_dir=${prev_file:h}
|
||||||
if ! [[ ${PWD:A}/ == ${prev_dir}/* ]]; then
|
if ! [[ ${PWD}/ == ${prev_dir}/* ]]; then
|
||||||
local env_file_leave=$prev_dir/$AUTOENV_FILE_LEAVE
|
local env_file_leave=$prev_dir/$AUTOENV_FILE_LEAVE
|
||||||
if _autoenv_check_authorized_env_file $env_file_leave; then
|
if _autoenv_check_authorized_env_file $env_file_leave; then
|
||||||
_autoenv_source $env_file_leave leave $prev_dir
|
_autoenv_source $env_file_leave leave $prev_dir
|
||||||
|
@ -33,5 +33,8 @@ Check that symlinked dirs get handled correctly.
|
|||||||
$ cd sub_linked
|
$ cd sub_linked
|
||||||
ENTERED: PWD:sub_linked pwd:sub_linked from:cwd.t to:sub_linked event:enter
|
ENTERED: PWD:sub_linked pwd:sub_linked from:cwd.t to:sub_linked event:enter
|
||||||
$ cd sub2
|
$ cd sub2
|
||||||
ENTERED: PWD:sub2 pwd:sub2 from:sub_linked to:sub2 event:enter
|
|
||||||
$ cd .
|
$ cd ../..
|
||||||
|
LEFT: PWD:cwd.t pwd:cwd.t from:sub2 to:cwd.t event:leave
|
||||||
|
$ cd sub_linked/sub2
|
||||||
|
ENTERED: PWD:sub2 pwd:sub2 from:cwd.t to:sub2 event:enter
|
||||||
|
@ -88,3 +88,28 @@ Test that .env is sourced only once with AUTOENV_HANDLE_LEAVE=0.
|
|||||||
ENTERED
|
ENTERED
|
||||||
$ cd ..
|
$ cd ..
|
||||||
$ cd sub
|
$ cd sub
|
||||||
|
|
||||||
|
|
||||||
|
Test that "leave" is not triggered when entering an outside dir via symlink.
|
||||||
|
|
||||||
|
$ AUTOENV_HANDLE_LEAVE=1
|
||||||
|
$ cd ..
|
||||||
|
LEFT
|
||||||
|
$ mkdir outside
|
||||||
|
$ cd outside
|
||||||
|
$ echo 'echo ENTERED outside: PWD:${PWD:t} pwd:${${"$(pwd)"}:t} from:${autoenv_from_dir:t} to:${autoenv_to_dir:t} event:${autoenv_event}' > .env
|
||||||
|
$ echo 'echo LEFT outside: PWD:${PWD:t} pwd:${${"$(pwd)"}:t} from:${autoenv_from_dir:t} to:${autoenv_to_dir:t} event:${autoenv_event}' > .env.leave
|
||||||
|
$ test_autoenv_auth_env_files
|
||||||
|
|
||||||
|
$ cd ..
|
||||||
|
$ ln -s ../outside sub/symlink
|
||||||
|
$ cd sub
|
||||||
|
ENTERED
|
||||||
|
$ cd symlink
|
||||||
|
ENTERED outside: PWD:symlink pwd:symlink from:sub to:symlink event:enter
|
||||||
|
|
||||||
|
$ cd ../..
|
||||||
|
LEFT
|
||||||
|
LEFT outside: PWD:leave.t pwd:leave.t from:symlink to:leave.t event:leave
|
||||||
|
$ cd sub/symlink
|
||||||
|
ENTERED outside: PWD:symlink pwd:symlink from:leave.t to:symlink event:enter
|
||||||
|
Loading…
Reference in New Issue
Block a user