Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Sayegh7
Copy link
Contributor

@Sayegh7 Sayegh7 commented Jan 21, 2019

This PR fixes #1962.

It handles the following cases while installing nvm:

  • If NVM_DIR is defined and set to anything other than the default value, exit installation
  • If NVM_DIR is defined and set to a file location not a directory, exit installation
  • Otherwise if NVM_DIR doesn't already exist, create the folder
  • Otherwise, continue

@ljharb ljharb added the installing nvm Problems installing nvm itself label Jan 21, 2019
install.sh Outdated
nvm_do_install() {
if [ -n "${NVM_DIR-}" ] && ! [ -d "${NVM_DIR}" ]; then
echo >&2 "You have \$NVM_DIR set to \"${NVM_DIR}\", but that directory does not exist. Check your profile files and environment."
# If NVM_DIR is set to something other than the default, exit
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem like the right behavior - it's expected and by design that a user setting NVM_DIR beforehand can alter the location in which nvm is installed.

The specific thing that's a problem is when the specified override directory does not exist (and this PR is, I believe, hoping to skip that error checking when the directory doesn't exist but it's the default path)

Copy link
Contributor Author

@Sayegh7 Sayegh7 Jan 21, 2019

Choose a reason for hiding this comment

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

If NVM_dir is defined and it is NOT what the installer would set it to (i.e. "$HOME/.nvm"), complain and exit

#1962 (comment)
This comment in the issue had the above suggestion and I assumed this is the required behavior.

So what would the correct behavior be if I ignore that comment? Should I attempt to create the specified override directory if it does not exist only?

Copy link
Member

Choose a reason for hiding this comment

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

The only time I think it's reasonable to create the directory is if it a) does not exist and b) is what the default would be anyways. If it does not exist, and is not the default, I think the current behavior should remain.

@Sayegh7
Copy link
Contributor Author

Sayegh7 commented Jan 21, 2019

@ljharb I corrected the behavior and added a check for the case when NVM_DIR is the default but points to a file.

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.

I've made some tweaks; let me know if this still matches what you hope :-)

if [ -n "${NVM_DIR-}" ] && ! [ -d "${NVM_DIR}" ]; then
echo >&2 "You have \$NVM_DIR set to \"${NVM_DIR}\", but that directory does not exist. Check your profile files and environment."
exit 1
if [ -e "${NVM_DIR}" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

I moved this logic up; if it's a non-directory file, we always want to error out.

type "$1" > /dev/null 2>&1
}

nvm_default_install_dir() {
Copy link
Member

Choose a reason for hiding this comment

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

I moved this logic here, so that both of the legitimate defaults could be respected without hardcoding either more than once.

@Sayegh7
Copy link
Contributor Author

Sayegh7 commented Jan 22, 2019

@ljharb Seems good to me 😄

@ljharb ljharb merged commit 66d2909 into nvm-sh:master Jan 22, 2019
@NKjoep NKjoep mentioned this pull request Nov 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

installing nvm Problems installing nvm itself

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Install script seems overly restrictive when NPM_DIR already set

2 participants