Merge pull request #847 from lukechilds/uninstall-bug
[New] `nvm uninstall`: Check installation dir permissions before uninstalling
commit
86c8b116d1
21
nvm.sh
21
nvm.sh
|
@ -1828,6 +1828,27 @@ 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 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.
|
# 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.*" \
|
||||||
|
|
|
@ -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
|
|
@ -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"
|
|
@ -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"
|
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
. ../../../nvm.sh
|
||||||
|
nvm install 0.12.7
|
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
. ../../../nvm.sh
|
||||||
|
nvm uninstall 0.12.7
|
||||||
|
nvm deactivate
|
Loading…
Reference in New Issue