mirror of
				https://github.com/nvm-sh/nvm.git
				synced 2025-10-31 10:00:06 +08:00 
			
		
		
		
	Check permissions in shell rather than using find -exec
This commit is contained in:
		
							
								
								
									
										14
									
								
								nvm.sh
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								nvm.sh
									
									
									
									
									
								
							| @@ -1830,8 +1830,18 @@ nvm() { | ||||
|       fi | ||||
|  | ||||
|       # Check version dir permissions | ||||
|       local FILES_WITHOUT_WRITE_PERMISIONS="$(find "$VERSION_PATH" -exec [ ! -w "{}" ] \; -exec echo "{}" \;)" | ||||
|       if [ "$FILES_WITHOUT_WRITE_PERMISIONS" ]; then | ||||
|       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 | ||||
|         >&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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user