Skip to content
Myr

[Refactor] make `check_file_permissions` be pure instead of relying on a closure.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Also, make it return early, to be a bit more efficient. (from #847)

authored by Jordan Harband · committed by Jordan Harband · parent 86c8b11 · Browse files · 1 file+16 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+16 added−14 removed

  • other:+16 added−14 removed

1 file+16 added−14 removed

modified:nvm.sh+16 added-14 removed
1533 unmodified lines
1534 ;;1535 esac1536}15371538# Check version dir permissions1539nvm_check_file_permissions() {1540 for FILE in $1/* $1/.[!.]* $1/..?* ; do1541 if [ -d "$FILE" ]; then1542 if ! nvm_check_file_permissions "$FILE"; then1543 return 21544 fi1545 elif [ -e "$FILE" ] && [ ! -w "$FILE" ]; then1546 return 11547 fi1548 done1549 return 01550}15511552nvm() {1553 if [ $# -lt 1 ]; then1554 nvm help1555 return
286 unmodified lines
1842 NVM_PREFIX="$(nvm_node_prefix)"1843 NVM_SUCCESS_MSG="Uninstalled node $VERSION"1844 fi18451832 # Check version dir permissions1833 local PERMISSIONS_OK=true1834 check_file_permissions() {1835 for FILE in $1/* $1/.[!.]* $1/..?* ; do1836 if [ -d "$FILE" ]; then1837 check_file_permissions "$FILE"1838 elif [ -e "$FILE" ]; then1839 [ ! -w "$FILE" ] && PERMISSIONS_OK=false1840 fi1841 done1842 }1843 check_file_permissions "$VERSION_PATH"1844 if [ "$PERMISSIONS_OK" = false ]; then1846 if ! nvm_check_file_permissions "$VERSION_PATH"; then1847 >&2 echo 'Cannot uninstall, incorrect permissions on installation folder.'1848 >&2 echo 'This is usually caused by running `npm install -g` as root. Run the following command as root to fix the permissions and then try again.'1849 >&2 echo1850 >&2 echo " chown -R $(whoami) \"$VERSION_PATH\""
534 unmodified lines
2385 nvm_is_iojs_version nvm_is_alias \2386 nvm_ls_remote nvm_ls_remote_iojs nvm_ls_remote_index_tab \2387 nvm_ls nvm_remote_version nvm_remote_versions \2388 nvm_install_iojs_binary nvm_install_node_binary \2387 nvm_install_node_source \2389 nvm_install_node_source nvm_check_file_permissions \2390 nvm_version nvm_rc_version nvm_match_version \2391 nvm_ensure_default_set nvm_get_arch nvm_get_os \2392 nvm_print_implicit_alias nvm_validate_implicit_alias \2393 nvm_resolve_alias nvm_ls_current nvm_alias \
72 unmodified lines