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

[Refactor] minor "if" and "return" improvement #1486

Merged
merged 1 commit into from
Apr 8, 2017

Conversation

PeterDaveHello
Copy link
Collaborator

No description provided.

nvm.sh Outdated
setopt nomatch
fi
return 2
if [ -d "$FILE" ] && ! nvm_check_file_permissions "$FILE"; 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 isn't the same; if the file is a directory but nvm_check_file_permissions returns true, i don't want anything to happen. With this change, it ends up hitting the else branch.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Really, I think here is no else branch?

Copy link
Member

Choose a reason for hiding this comment

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

aha, sorry, you're right, there's no else.

However, in the original code, if the file is a directory, nothing happened outside of the nvm_check_file_permissions branch - in your new code, if the file is a directory but the permissions check fails, it falls to the elif - which checks that it exists, and is not writable and not owned (possible for a directory), which means the file-related error message would be printed.

Am I reading this incorrectly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're correct, reverted this part, thanks.

nvm.sh Outdated
fi

if [ -n "${NPM_CONFIG_PREFIX-}" ] && ! (nvm_tree_contains_path "$NVM_DIR" "$NPM_CONFIG_PREFIX" >/dev/null 2>&1); then
elif [ -n "${NPM_CONFIG_PREFIX-}" ] && ! (nvm_tree_contains_path "$NVM_DIR" "$NPM_CONFIG_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.

I don't think we need all these elifs; I actually prefer the separate if blocks here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok, reverted both above

@PeterDaveHello PeterDaveHello force-pushed the refactor branch 2 times, most recently from a10a5ef to 315f0df Compare April 6, 2017 06:44
@ljharb ljharb merged commit e87f395 into nvm-sh:master Apr 8, 2017
@PeterDaveHello PeterDaveHello deleted the refactor branch April 8, 2017 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants