Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjust for symbolic links #2143

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,12 @@ nvm_tree_contains_path() {
previous_pathdir="${node_path}"
local pathdir
pathdir=$(dirname "${previous_pathdir}")

# get real directory in case of symbolic links
if [ -d "${pathdir-}" ]; then
aiqui marked this conversation as resolved.
Show resolved Hide resolved
pathdir="$(nvm_cd -P "${pathdir}" && pwd)"
fi

while [ "${pathdir}" != '' ] && [ "${pathdir}" != '.' ] && [ "${pathdir}" != '/' ] &&
[ "${pathdir}" != "${tree}" ] && [ "${pathdir}" != "${previous_pathdir}" ]; do
previous_pathdir="${pathdir}"
Expand Down
6 changes: 6 additions & 0 deletions test/fast/Unit tests/nvm_tree_contains_path
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/sh

cleanup () {
rm tmp3/tmp2
rmdir tmp3
rm tmp/node
rmdir tmp
rm tmp2/node
Expand All @@ -14,6 +16,8 @@ mkdir -p tmp
touch tmp/node
mkdir -p tmp2
touch tmp2/node
mkdir -p tmp3
ln -s tmp2 tmp3/

[ "$(nvm_tree_contains_path 2>&1)" = "both the tree and the node path are required" ] || die 'incorrect error message with no args'
[ "$(nvm_tree_contains_path > /dev/null 2>&1 ; echo $?)" = "2" ] || die 'incorrect error code with no args'
Expand All @@ -28,4 +32,6 @@ nvm_tree_contains_path tmp2 tmp2/node || die '"tmp2" should contain "tmp2/node"'

nvm_tree_contains_path tmp2 tmp/node && die '"tmp2" should not contain "tmp/node"'

nvm_tree_contains_path tmp2 tmp3 && die 'no idea'

cleanup