mirror of
				https://github.com/nvm-sh/nvm.git
				synced 2025-10-31 10:00:06 +08:00 
			
		
		
		
	[Refactor] make check_file_permissions be pure instead of relying on a closure.
				
					
				
			Also, make it return early, to be a bit more efficient. (from #847)
This commit is contained in:
		
							
								
								
									
										30
									
								
								nvm.sh
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								nvm.sh
									
									
									
									
									
								
							| @@ -1535,6 +1535,20 @@ nvm_is_natural_num() { | ||||
|   esac | ||||
| } | ||||
|  | ||||
| # Check version dir permissions | ||||
| nvm_check_file_permissions() { | ||||
|   for FILE in $1/* $1/.[!.]* $1/..?* ; do | ||||
|       if [ -d "$FILE" ]; then | ||||
|         if ! nvm_check_file_permissions "$FILE"; then | ||||
|           return 2 | ||||
|         fi | ||||
|       elif [ -e "$FILE" ] && [ ! -w "$FILE" ]; then | ||||
|         return 1 | ||||
|       fi | ||||
|   done | ||||
|   return 0 | ||||
| } | ||||
|  | ||||
| nvm() { | ||||
|   if [ $# -lt 1 ]; then | ||||
|     nvm help | ||||
| @@ -1829,19 +1843,7 @@ nvm() { | ||||
|         NVM_SUCCESS_MSG="Uninstalled node $VERSION" | ||||
|       fi | ||||
|  | ||||
|       # Check version dir permissions | ||||
|       local PERMISSIONS_OK=true | ||||
|       check_file_permissions() { | ||||
|         for FILE in $1/* $1/.[!.]* $1/..?* ; do | ||||
|             if [ -d "$FILE" ]; then | ||||
|               check_file_permissions "$FILE" | ||||
|             elif [ -e "$FILE" ]; then | ||||
|               [ ! -w "$FILE" ] && PERMISSIONS_OK=false | ||||
|             fi | ||||
|         done | ||||
|       } | ||||
|       check_file_permissions "$VERSION_PATH" | ||||
|       if [ "$PERMISSIONS_OK" = false ]; then | ||||
|       if ! nvm_check_file_permissions "$VERSION_PATH"; then | ||||
|         >&2 echo 'Cannot uninstall, incorrect permissions on installation folder.' | ||||
|         >&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.' | ||||
|         >&2 echo | ||||
| @@ -2384,7 +2386,7 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | command grep -v "N/A" | command sed '/^$/d' | ||||
|         nvm_ls_remote nvm_ls_remote_iojs nvm_ls_remote_index_tab \ | ||||
|         nvm_ls nvm_remote_version nvm_remote_versions \ | ||||
|         nvm_install_iojs_binary nvm_install_node_binary \ | ||||
|         nvm_install_node_source \ | ||||
|         nvm_install_node_source nvm_check_file_permissions \ | ||||
|         nvm_version nvm_rc_version nvm_match_version \ | ||||
|         nvm_ensure_default_set nvm_get_arch nvm_get_os \ | ||||
|         nvm_print_implicit_alias nvm_validate_implicit_alias \ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user