scripts/wrapper in rvm-0.1.41 vs scripts/wrapper in rvm-0.1.42

- old
+ new

@@ -26,22 +26,25 @@ if [[ -f $file_name ]] ; then chmod +x $file_name ; fi } symlink_binary() { # Generate the default wrapper with the given binary name. - wrap_binary # Note, now forcing this every time to force clean. - # Then symlink it into place. - rm -f "${rvm_bin_path}/${prefix}_${binary_name}" - ln -fs "$file_name" "${rvm_bin_path}/${prefix}_${binary_name}" + # We first check if we can wrap the binary and if we were able to, + # we then symlink it into place. + if wrap_binary && [[ -f "$file_name" ]]; then + rm -f "${rvm_bin_path}/${prefix}_${binary_name}" + ln -fs "$file_name" "${rvm_bin_path}/${prefix}_${binary_name}" + fi } wrap_binary() { - # Iff the command is found in the path. - if command -v $binary_name > /dev/null; then + # We wrap when the given binary is in the path or override_check is set to one. + if [[ "$override_check" = "1" ]] || command -v $binary_name > /dev/null; then wrap else $rvm_scripts_path/log "error" "Binary '$binary_name' not found in path." + return 1 fi } usage() { printf "Usage: 'rvm wrapper [ruby_string] [wrapper_prefix] [binary[ binary[ ...]]]'\n" @@ -56,12 +59,13 @@ exit 1 fi ruby_string="$1"; shift +override_check=0 prefix="$1" -if [[ -n "$1" ]]; then shift; fi +[[ "$#" -gt 0 ]] && shift binaries="$(echo "$@" | __rvm_strip)" if [[ 'system' == '$ruby_string' ]]; then $rvm_scripts_path/log "error" "Wrapper can't be called with system rubies - sorry!" @@ -83,22 +87,21 @@ # For each binary, we want to generate the wrapper / symlink # it to the existing wrapper if needed. for binary_name in $binaries; do file_name="${rvm_wrappers_path}/${environment_identifier}/${binary_name}" if [[ -z "$prefix" ]] ; then + override_check=1 wrap_binary # Symlink it into place. - if [[ "$binary_name" == "ruby" ]] ; then - rm -f "${rvm_bin_path}/${environment_identifier}" - ln -nsf "${file_name}" "${rvm_bin_path}/${environment_identifier}" - else - rm -f "${rvm_bin_path}/${binary_name}-${environment_identifier}" - ln -nsf "${file_name}" "${rvm_bin_path}/${binary_name}-${environment_identifier}" - fi - if [[ "root" = "$(whoami)" ]] && [[ "${default_flag}" = 1 ]] ; then - rm -f "${rvm_bin_path}/${binary_name}" - ln -nsf "${file_name}" "${rvm_bin_path}/${binary_name}" - fi + if [[ -f "$file_name" ]]; then + if [[ "$binary_name" == "ruby" ]] ; then + destination="$rvm_bin_path/$environment_identifier" + else + destination="$rvm_bin_path/${binary_name}-${environment_identifier}" + fi + rm -rf "$destination" + ln -nsf "$file_name" "$destination" + fi; unset destination else symlink_binary fi ; unset file_name done