From ab7b4daf17153131f051037c1ed7767eb9e3632a Mon Sep 17 00:00:00 2001 From: Charlie Hileman Date: Wed, 8 Jan 2020 12:06:49 -0500 Subject: [PATCH 1/2] [Fix] `nvm_tree_contains_path`: handle symbolic links Co-Authored-By: Charlie Hileman Co-Authored-By: Jordan Harband --- nvm.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nvm.sh b/nvm.sh index 83aac75..e671a8a 100644 --- a/nvm.sh +++ b/nvm.sh @@ -311,6 +311,12 @@ nvm_tree_contains_path() { local pathdir pathdir=$(dirname "${node_path}") + + # get real directory in case of symbolic links + if [ -d "${pathdir-}" ]; then + pathdir="$(nvm_cd -P "${pathdir}" && pwd)" + fi + while [ "${pathdir}" != "" ] && [ "${pathdir}" != "." ] && [ "${pathdir}" != "/" ] && [ "${pathdir}" != "${tree}" ]; do pathdir=$(dirname "${pathdir}") done From e7e5b372e92421184109bcea877fc8e9c3764932 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 12 Jan 2020 13:29:35 -0800 Subject: [PATCH 2/2] [Tests] add some WIP tests --- test/fast/Unit tests/nvm_tree_contains_path | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/fast/Unit tests/nvm_tree_contains_path b/test/fast/Unit tests/nvm_tree_contains_path index 9b40854..08bfed8 100755 --- a/test/fast/Unit tests/nvm_tree_contains_path +++ b/test/fast/Unit tests/nvm_tree_contains_path @@ -1,6 +1,8 @@ #!/bin/sh cleanup () { + rm tmp3/tmp2 + rmdir tmp3 rm tmp/node rmdir tmp rm tmp2/node @@ -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' @@ -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