-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
[Fix] nvm_die_on_prefix
: use directory comparison rather than string
#2316
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@@ -2230,7 +2231,7 @@ nvm_die_on_prefix() { | |||
local NVM_OS | |||
NVM_OS="$(nvm_get_os)" | |||
NVM_NPM_PREFIX="$(npm config --loglevel=warn get prefix)" | |||
if [ "${NVM_VERSION_DIR}" != "${NVM_NPM_PREFIX}" ] && ! (nvm_tree_contains_path "${NVM_VERSION_DIR}" "${NVM_NPM_PREFIX}" >/dev/null 2>&1); then | |||
if [ ! "${NVM_VERSION_DIR}" -ef "${NVM_NPM_PREFIX}" ] && ! (nvm_tree_contains_path "${NVM_VERSION_DIR}" "${NVM_NPM_PREFIX}" >/dev/null 2>&1); then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will need tests that fail without the change - NVM_VERSION_DIR should never have a trailing slash in the first place (directories don't have slashes; the slash means the contents of the directory), and i'm not sure what else -ef
does (do you have docs for it that demonstrate it's in posix and describe its semantics?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html
https://tldp.org/LDP/abs/html/fto.html
I can't find when it was created in any documentation, but based on stackexchange threads, it's fully compatible with all shells.
It checks if 2 files refer to the same device and inode numbers.
This can be tested manually in all posix-shells with:
# Prints
test "$PWD" -ef . && echo 'hello'
# Doesn't print
test "$PWD/../" -ef . && echo 'hello'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this seems useful. There's probably other places that could use this change, like nvm_tree_contains_path
, and nvm_find_up
etc.
I've rebased this; the first commit (the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
nvm_die_on_prefix
: use directory comparison rather than string
Fixes #2315
This changes out a string comparison to a directory comparison, removes empty lines from versions, and removes trailing slashes from versions.