Commit 83728089 authored by Sam Stephenson's avatar Sam Stephenson
Browse files

Confirm reinstalling already-installed versions unless invoked with --force

parent 5fd4ec64
Loading
Loading
Loading
Loading
+19 −2
Original line number Diff line number Diff line
@@ -2,11 +2,12 @@
#
# Summary: Install a Ruby version using the ruby-build plugin
#
# Usage: rbenv install [-k|--keep] [-v|--verbose] <version>
#        rbenv install [-k|--keep] [-v|--verbose] /path/to/definition
# Usage: rbenv install [-f|--force] [-k|--keep] [-v|--verbose] <version>
#        rbenv install [-f|--force] [-k|--keep] [-v|--verbose] <definition-file>
#        rbenv install -l|--list
#
#   -l/--list        List all available versions
#   -f/--force       Install even if the version appears to be installed already
#   -k/--keep        Keep source tree in $RBENV_BUILD_ROOT after installation
#                    (defaults to $RBENV_ROOT/sources)
#   -v/--verbose     Verbose mode: print compilation status to stdout
@@ -36,6 +37,7 @@ usage() {
  [ -z "$1" ] || exit "$1"
}

unset FORCE
unset KEEP
unset VERBOSE

@@ -50,6 +52,9 @@ for option in "${OPTIONS[@]}"; do
    ruby-build --definitions | sed 's/^/  /'
    exit
    ;;
  "f" | "force" )
    FORCE=true
    ;;
  "k" | "keep" )
    [ -n "${RBENV_BUILD_ROOT}" ] || RBENV_BUILD_ROOT="${RBENV_ROOT}/sources"
    ;;
@@ -102,6 +107,18 @@ done
[ -n "$VERSION_NAME" ] || VERSION_NAME="${DEFINITION##*/}"
PREFIX="${RBENV_ROOT}/versions/${VERSION_NAME}"

# If the installation prefix exists, prompt for confirmation unless
# the --force option was specified.
if [ -z "$FORCE" ] && [ -d "${PREFIX}/bin" ]; then
  echo "rbenv: $PREFIX already exists" >&2
  read -p "continue with installation? (y/N) "

  case "$REPLY" in
  y* | Y* ) ;;
  * ) exit 1 ;;
  esac
fi

# If RBENV_BUILD_ROOT is set, always pass keep options to ruby-build.
if [ -n "${RBENV_BUILD_ROOT}" ]; then
  export RUBY_BUILD_BUILD_PATH="${RBENV_BUILD_ROOT}/${VERSION_NAME}"
+2 −2
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
#
# Summary: Uninstall a specific Ruby version
#
# Usage: rbenv uninstall [-f] <version>
# Usage: rbenv uninstall [-f|--force] <version>
#
#    -f  Attempt to remove the specified version without prompting
#        for confirmation. If the version does not exist, do not
@@ -22,7 +22,7 @@ if [ -z "$RBENV_ROOT" ]; then
fi

unset FORCE
if [ "$1" = "-f" ]; then
if [ "$1" = "-f" ] || [ "$1" = "--force" ]; then
  FORCE=true
  shift
fi