Check dir permissions before attempting to nvm uninstall

Luke Childs 2016-04-17 22:22:37 +01:00
parent d3e334d86d
commit 005e29a223
1 changed files with 11 additions and 0 deletions

11
nvm.sh
View File

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