Skip to content
Myr

Merge pull request #847 from lukechilds/uninstall-bug

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

[New] `nvm uninstall`: Check installation dir permissions before uninstalling

authored by Jordan Harband · committed by Jordan Harband · parents d3e334d, 3a2d35f · Browse files · 6 files+102 added−0 removed
This commit

State

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

Diff stats

6 files+102 added−0 removed

  • tests:+81 added−0 removed
  • other:+21 added−0 removed

6 files+102 added−0 removed

added:test/fast/Running "nvm uninstall" with incorrect file permissions fails nicely+14 added
1#!/bin/sh23cd ../..4mkdir v0.0.15mkdir src/node-v0.0.167sudo touch v0.0.1/sudo89. ./nvm.sh1011RETURN_MESSAGE="$(nvm uninstall v0.0.1 2>&1)"12CHECK_FOR="Cannot uninstall, incorrect permissions on installation folder"1314test "${RETURN_MESSAGE#*$CHECK_FOR}" != "$RETURN_MESSAGE" || exit 1
added:test/slow/nvm uninstall/Running "nvm uninstall 0.12.6" uninstalls v0.12.6+28 added
1#!/bin/sh23die () { echo $@ ; exit 1; }45# Source nvm6. ../../../nvm.sh78# Version to install/uninstall9NVM_TEST_VERSION=0.12.61011# Make sure it's not already here12[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION1314# Install it15nvm install $NVM_TEST_VERSION1617# Make sure it installed18nvm ls | grep "$NVM_TEST_VERSION" || die "Failed to install node"1920# Switch to another version so we can uninstall21nvm use 0.12.72223# Uninstall it24nvm uninstall $NVM_TEST_VERSION2526# Make sure it uninstalled27nvm ls | grep "$NVM_TEST_VERSION"28[ "$?" != "0" ] || die "Failed to uninstall node"
added:test/slow/nvm uninstall/Running "nvm uninstall" with incorrect file permissions fails nicely+30 added
1#!/bin/sh23die () { echo $@ ; exit 1; }45# Source nvm6. ../../../nvm.sh78# Version to install/uninstall9NVM_TEST_VERSION=5.10.11011# Make sure it's not already here12[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION1314# Install it15nvm install $NVM_TEST_VERSION1617# Make sure it installed18nvm ls | grep "$NVM_TEST_VERSION" || die "Failed to install node"1920# Install global module as root21npm_path=$(which npm)22sudo "$npm_path" install jspm -g2324# Switch to another version so we can uninstall25nvm use 0.12.72627# Attempt to uninstall it28RETURN_MESSAGE="$(nvm uninstall $NVM_TEST_VERSION 2>&1)"29CHECK_FOR="Cannot uninstall, incorrect permissions on installation folder"30test "${RETURN_MESSAGE#*$CHECK_FOR}" != "$RETURN_MESSAGE" || die "Failed to show error message"
added:test/slow/nvm uninstall/setup_dir+4 added
1#!/bin/sh23. ../../../nvm.sh4nvm install 0.12.7
added:test/slow/nvm uninstall/teardown_dir+5 added
1#!/bin/sh23. ../../../nvm.sh4nvm uninstall 0.12.75nvm deactivate
modified:nvm.sh+21 added
1826 unmodified lines
1827 else1828 NVM_PREFIX="$(nvm_node_prefix)"1829 NVM_SUCCESS_MSG="Uninstalled node $VERSION"1830 fi18311832 # 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 ]; then1845 >&2 echo 'Cannot uninstall, incorrect permissions on installation folder.'1846 >&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.'1847 >&2 echo1848 >&2 echo " chown -R $(whoami) \"$VERSION_PATH\""1849 return 11850 fi18511852 # Delete all files related to target version.1853 command rm -rf "$NVM_DIR/src/$NVM_PREFIX-$VERSION" \1854 "$NVM_DIR/src/$NVM_PREFIX-$VERSION.tar.*" \1855 "$NVM_DIR/bin/$NVM_PREFIX-${t}" \
608 unmodified lines