Skip to content

Conversation

dylanarmstrong
Copy link
Contributor

@dylanarmstrong dylanarmstrong commented Oct 9, 2020

Fixes #2315

This changes out a string comparison to a directory comparison, removes empty lines from versions, and removes trailing slashes from versions.

Copy link
Member

@ljharb ljharb left a 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
Copy link
Member

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?

Copy link
Contributor Author

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'

Copy link
Member

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.

@ljharb ljharb added the needs followup We need some info or action from whoever filed this issue/PR. label Oct 10, 2020
@ljharb
Copy link
Member

ljharb commented Oct 11, 2020

I've rebased this; the first commit (the unsetopt) now LGTM, but the second commit (the -ef change) needs its own test.

@ljharb ljharb removed the needs followup We need some info or action from whoever filed this issue/PR. label Oct 12, 2020
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ljharb ljharb changed the title fix: fixes 2315 by using directory comparison rather than string [Fix] nvm_die_on_prefix: use directory comparison rather than string Oct 12, 2020
@ljharb ljharb added the hacktoberfest-accepted If you're interested in a free shirt, this PR counts towards it. label Oct 12, 2020
@ljharb ljharb merged commit e01060f into nvm-sh:master Oct 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted If you're interested in a free shirt, this PR counts towards it.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MacOS Prefix NVM_VERSION_DIR != NVM_NPM_PREFIX
2 participants