mirror of
				https://github.com/nvm-sh/nvm.git
				synced 2025-10-31 18:25:52 +08:00 
			
		
		
		
	Check dir permissions before attempting to nvm uninstall
This commit is contained in:
		
							
								
								
									
										11
									
								
								nvm.sh
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								nvm.sh
									
									
									
									
									
								
							| @@ -1828,6 +1828,17 @@ nvm() { | |||||||
|         NVM_PREFIX="$(nvm_node_prefix)" |         NVM_PREFIX="$(nvm_node_prefix)" | ||||||
|         NVM_SUCCESS_MSG="Uninstalled node $VERSION" |         NVM_SUCCESS_MSG="Uninstalled node $VERSION" | ||||||
|       fi |       fi | ||||||
|  |  | ||||||
|  |       # Check version dir permissions | ||||||
|  |       local FILES_WITHOUT_WRITE_PERMISIONS="$(find "$VERSION_PATH" -exec [ ! -w "{}" ] \; -exec echo "{}" \;)" | ||||||
|  |       if [ "$FILES_WITHOUT_WRITE_PERMISIONS" ]; 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 | ||||||
|  |         >&2 echo "  chown -R $(whoami) \"$VERSION_PATH\"" | ||||||
|  |         return 1 | ||||||
|  |       fi | ||||||
|  |  | ||||||
|       # Delete all files related to target version. |       # Delete all files related to target version. | ||||||
|       command rm -rf "$NVM_DIR/src/$NVM_PREFIX-$VERSION" \ |       command rm -rf "$NVM_DIR/src/$NVM_PREFIX-$VERSION" \ | ||||||
|              "$NVM_DIR/src/$NVM_PREFIX-$VERSION.tar.*" \ |              "$NVM_DIR/src/$NVM_PREFIX-$VERSION.tar.*" \ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user