scripts/wrapper in rvm-0.1.38 vs scripts/wrapper in rvm-0.1.39
- old
+ new
@@ -1,7 +1,8 @@
#!/usr/bin/env bash
+default_flag="$rvm_default_flag"
# Prevent it from recursing.
unset rvm_default_flag rvm_wrapper_name
source $rvm_scripts_path/initialize
source $rvm_scripts_path/utility
@@ -16,21 +17,28 @@
}
wrap() {
mkdir -p "$(dirname "$file_name")"
rm -f "$file_name"
- printf "#!/usr/bin/env sh\n" > "$file_name"
- printf "source \"${rvm_environments_path}/${environment_identifier}\"\n" >> "$file_name"
- printf "exec $binary_name \"\$@\"\n" >> "$file_name"
+ echo "#!/usr/bin/env sh" > "$file_name"
+ echo "if [ -s \"${rvm_environments_path}/${environment_identifier}\" ] ; then" >> "$file_name"
+ echo " . \"${rvm_environments_path}/${environment_identifier}\"" >> "$file_name"
+ echo " exec $binary_name \"\$@\"" >> "$file_name"
+ echo "else" >> $file_name
+ echo " echo \"ERROR: Missing RVM environment file: '${rvm_environments_path}/${environment_identifier}'\"" >> $file_name
+ echo " exit 1" >> $file_name
+ echo "fi" >> $file_name
+
if [[ -f $file_name ]] ; then chmod +x $file_name ; fi
}
symlink_binary() {
# Generate the default wrapper with the given binary name.
- [[ ! -f "$file_name" ]] && wrap_binary
+ 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}"
}
wrap_binary() {
# Iff the command is found in the path.
@@ -46,10 +54,11 @@
printf " Where binary defaults to ruby, gem, rake, irb, rdoc, ri, testrb\n"
printf " For more information, see 'rvm help wrapper'\n"
}
# Empty ruby string: show usage and exit.
+
if [[ -z "$1" ]]; then
usage
exit 1
fi
@@ -82,17 +91,22 @@
for binary_name in $binaries; do
file_name="${rvm_wrappers_path}/${environment_identifier}/${binary_name}"
if [[ -z "$prefix" ]] ; then
wrap_binary
# Symlink it into place.
- if [[ "$binary_name" == "ruby" ]]; then
- ln -sf "$file_name" "$rvm_bin_path/$environment_identifier"
+ if [[ "$binary_name" == "ruby" ]] ; then
+ rm -f "${rvm_bin_path}/${environment_identifier}"
+ ln -nsf "${file_name}" "${rvm_bin_path}/${environment_identifier}"
else
- ln -sf "$file_name" "$rvm_bin_path/$binary_name-$environment_identifier"
+ 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
else
symlink_binary
- fi
- unset file_name
+ fi ; unset file_name
done
exit $?