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
Provenance
- Commit
86c8b11- Tree
e3f70d8- Author
Jordan Harband <ljharb@gmail.com>- Committer
Jordan Harband <ljharb@gmail.com>- Parent 1
d3e334d- Parent 2
3a2d35f
6 files changed+102 added−0 removed
added:test/fast/Running "nvm uninstall" with incorrect file permissions fails nicely+14 added
1+#!/bin/sh2+3+cd ../..4+mkdir v0.0.15+mkdir src/node-v0.0.16+7+sudo touch v0.0.1/sudo8+9+. ./nvm.sh10+11+RETURN_MESSAGE="$(nvm uninstall v0.0.1 2>&1)"12+CHECK_FOR="Cannot uninstall, incorrect permissions on installation folder"13+14+test "${RETURN_MESSAGE#*$CHECK_FOR}" != "$RETURN_MESSAGE" || exit 1added:test/slow/nvm uninstall/Running "nvm uninstall 0.12.6" uninstalls v0.12.6+28 added
1+#!/bin/sh2+3+die () { echo $@ ; exit 1; }4+5+# Source nvm6+. ../../../nvm.sh7+8+# Version to install/uninstall9+NVM_TEST_VERSION=0.12.610+11+# Make sure it's not already here12+[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION13+14+# Install it15+nvm install $NVM_TEST_VERSION16+17+# Make sure it installed18+nvm ls | grep "$NVM_TEST_VERSION" || die "Failed to install node"19+20+# Switch to another version so we can uninstall21+nvm use 0.12.722+23+# Uninstall it24+nvm uninstall $NVM_TEST_VERSION25+26+# Make sure it uninstalled27+nvm 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/sh2+3+die () { echo $@ ; exit 1; }4+5+# Source nvm6+. ../../../nvm.sh7+8+# Version to install/uninstall9+NVM_TEST_VERSION=5.10.110+11+# Make sure it's not already here12+[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION13+14+# Install it15+nvm install $NVM_TEST_VERSION16+17+# Make sure it installed18+nvm ls | grep "$NVM_TEST_VERSION" || die "Failed to install node"19+20+# Install global module as root21+npm_path=$(which npm)22+sudo "$npm_path" install jspm -g23+24+# Switch to another version so we can uninstall25+nvm use 0.12.726+27+# Attempt to uninstall it28+RETURN_MESSAGE="$(nvm uninstall $NVM_TEST_VERSION 2>&1)"29+CHECK_FOR="Cannot uninstall, incorrect permissions on installation folder"30+test "${RETURN_MESSAGE#*$CHECK_FOR}" != "$RETURN_MESSAGE" || die "Failed to show error message"added:test/slow/nvm uninstall/setup_dir+4 added
1+#!/bin/sh2+3+. ../../../nvm.sh4+nvm install 0.12.7added:test/slow/nvm uninstall/teardown_dir+5 added
1+#!/bin/sh2+3+. ../../../nvm.sh4+nvm uninstall 0.12.75+nvm deactivatemodified:nvm.sh+21 added
1826 unmodified lines1827 else1828 NVM_PREFIX="$(nvm_node_prefix)"1829 NVM_SUCCESS_MSG="Uninstalled node $VERSION"1830 fi1831+1832+ # 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+ fi1851+1852 # 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