Merge pull request #847 from lukechilds/uninstall-bug

[New] `nvm uninstall`: Check installation dir permissions before uninstalling
Jordan Harband 2016-04-18 17:53:41 -07:00
commit 86c8b116d1
6 changed files with 102 additions and 0 deletions

21
nvm.sh
View File

@ -1828,6 +1828,27 @@ nvm() {
NVM_PREFIX="$(nvm_node_prefix)"
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
>&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.
command rm -rf "$NVM_DIR/src/$NVM_PREFIX-$VERSION" \
"$NVM_DIR/src/$NVM_PREFIX-$VERSION.tar.*" \

View File

@ -0,0 +1,14 @@
#!/bin/sh
cd ../..
mkdir v0.0.1
mkdir src/node-v0.0.1
sudo touch v0.0.1/sudo
. ./nvm.sh
RETURN_MESSAGE="$(nvm uninstall v0.0.1 2>&1)"
CHECK_FOR="Cannot uninstall, incorrect permissions on installation folder"
test "${RETURN_MESSAGE#*$CHECK_FOR}" != "$RETURN_MESSAGE" || exit 1

View File

@ -0,0 +1,28 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
# Source nvm
. ../../../nvm.sh
# Version to install/uninstall
NVM_TEST_VERSION=0.12.6
# Make sure it's not already here
[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION
# Install it
nvm install $NVM_TEST_VERSION
# Make sure it installed
nvm ls | grep "$NVM_TEST_VERSION" || die "Failed to install node"
# Switch to another version so we can uninstall
nvm use 0.12.7
# Uninstall it
nvm uninstall $NVM_TEST_VERSION
# Make sure it uninstalled
nvm ls | grep "$NVM_TEST_VERSION"
[ "$?" != "0" ] || die "Failed to uninstall node"

View File

@ -0,0 +1,30 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
# Source nvm
. ../../../nvm.sh
# Version to install/uninstall
NVM_TEST_VERSION=5.10.1
# Make sure it's not already here
[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION
# Install it
nvm install $NVM_TEST_VERSION
# Make sure it installed
nvm ls | grep "$NVM_TEST_VERSION" || die "Failed to install node"
# Install global module as root
npm_path=$(which npm)
sudo "$npm_path" install jspm -g
# Switch to another version so we can uninstall
nvm use 0.12.7
# Attempt to uninstall it
RETURN_MESSAGE="$(nvm uninstall $NVM_TEST_VERSION 2>&1)"
CHECK_FOR="Cannot uninstall, incorrect permissions on installation folder"
test "${RETURN_MESSAGE#*$CHECK_FOR}" != "$RETURN_MESSAGE" || die "Failed to show error message"

View File

@ -0,0 +1,4 @@
#!/bin/sh
. ../../../nvm.sh
nvm install 0.12.7

View File

@ -0,0 +1,5 @@
#!/bin/sh
. ../../../nvm.sh
nvm uninstall 0.12.7
nvm deactivate