scripts/gemsets in rvm-0.1.39 vs scripts/gemsets in rvm-0.1.40
- old
+ new
@@ -1,17 +1,64 @@
#!/usr/bin/env bash
-source $rvm_scripts_path/utility
-source $rvm_scripts_path/selector
+source "$rvm_scripts_path/base"
-if [[ ! -z "$rvm_trace_flag" ]] ; then set -x ; export rvm_trace_flag ; fi
rvm_ruby_gem_home="${rvm_ruby_gem_home:-$GEM_HOME}"
-
if [[ ! -d "$rvm_ruby_gem_home" ]] && command -v gem > /dev/null 2>&1; then rvm_ruby_gem_home="$(gem env home)" ; fi
-trap "if [[ -d $rvm_tmp_path/ ]] && [[ -s $rvm_tmp_path/$$ ]] ; then rm -f $rvm_tmp_path/$$ > /dev/null 2>&1 ; fi ; exit" 0 1 2 3 15
+usage() {
+ printf "Usage: 'rvm gemset action'\n"
+ printf " where action is one of: {import,export,create,copy,empty,delete,name,dir,list,gemdir,install,pristine,clear,use,update,globalcache}\n"
+ printf "\n"
+ printf " Tools for working with and manipulating gemsets within rvm.\n"
+ exit 1
+}
+gemset_update() {
+ if [[ -z "$rvm_ruby_strings" ]]; then
+ $rvm_scripts_path/log "info" "Running gem update for all rubies and gemsets."
+ rvm_ruby_strings="$(\ls "$rvm_gems_path" | grep -v '^\(doc\|cache\|@\|system\)' | tr '\n' ',')"
+ else
+ $rvm_scripts_path/log "info" "Running gem update for the specified rubies."
+ fi
+ export rvm_ruby_strings
+ $rvm_scripts_path/set "gem" "update"
+ return $?
+}
+
+gemset_globalcache() {
+ if [[ "$1" == "disable" ]]; then
+ $rvm_scripts_path/log "info" "Removing the global cache (note: this will empty the caches)"
+ for directory_name in $(\ls "$rvm_gems_path"); do
+ current_cache_path="$rvm_gems_path/$directory_name/cache"
+ if [[ -L "$current_cache_path" && "$(readlink "$current_cache_path")" == "$rvm_gems_cache_path" ]]; then
+ $rvm_scripts_path/log "info" "Reverting the gem cache for $directory_name to an empty directory."
+ rm -f "$current_cache_path" 2>/dev/null
+ mkdir -p "$current_cache_path" 2>/dev/null
+ fi
+ done; unset full_directory_path directory_name
+ $rvm_scripts_path/db "$rvm_config_path/user" "use_gemset_globalcache" "delete"
+ elif [[ "$1" == "enable" ]]; then
+ $rvm_scripts_path/log "info" "Enabling global cache for gems."
+ mkdir -p "$rvm_gems_cache_path"
+ for directory_name in $(\ls "$rvm_gems_path"); do
+ current_cache_path="$rvm_gems_path/$directory_name/cache"
+ if [[ -d "$current_cache_path" && ! -L "$current_cache_path" ]]; then
+ $rvm_scripts_path/log "info" "Moving the gem cache for $directory_name to the global cache."
+ mv "$current_cache_path/"*.gem "$rvm_gems_cache_path/" 2>/dev/null
+ rm -rf "$current_cache_path"
+ ln -nfs "$rvm_gems_cache_path" "$current_cache_path"
+ fi
+ done; unset full_directory_path directory_name
+ $rvm_scripts_path/db "$rvm_config_path/user" "use_gemset_globalcache" "true"
+ else
+ printf "Usage: 'rvm gemset globalcache {enable,disable}\n"
+ printf " Enable / Disable the use of a global gem cachedir.\n"
+ return 1
+ fi
+}
+
gemset_name() {
gemset_dir | awk -F${rvm_gemset_separator} '{print $2}'
}
gemset_dir() {
@@ -21,10 +68,18 @@
gemset_create() {
rvm_ruby_gem_prefix=$(echo $rvm_ruby_gem_home | sed 's/'${rvm_gemset_separator}'.*$//')
for gemset in $(echo $gems_args) ; do
gem_home="${rvm_ruby_gem_prefix}${rvm_gemset_separator}${gems_args/ /}"
mkdir -p $gem_home
+ # When the globalcache is enabled, we need to ensure we setup the cache directory correctly.
+ if __rvm_using_gemset_globalcache; then
+ if [[ -d "$gem_home/cache" && ! -L "$gem_home/cache" ]]; then
+ mv "$gem_home/cache"/*.gem "$rvm_gems_cache_path/" 2>/dev/null
+ rm -rf "$gem_home/cache"
+ fi
+ ln -nfs "$rvm_gems_cache_path" "$gem_home/cache"
+ fi
$rvm_scripts_path/log "info" "Gemset '$gemset' created."
done ; unset gem_home
}
gemset_list() {
@@ -174,11 +229,11 @@
else
$rvm_scripts_path/log "error" "No *.gems file found."
return 1
fi
- mkdir -p "$rvm_gems_path/cache" # Ensure the base cache dir is initialized.
+ mkdir -p "$rvm_gems_cache_path" # Ensure the base cache dir is initialized.
if [[ -s "$rvm_file_name" ]] ; then
echo "Importing $rvm_file_name file..."
rvm_ruby_gem_list=$(\ls $rvm_ruby_gem_home/specifications/ 2> /dev/null | sed 's#.gems.*$##' 2> /dev/null)
@@ -235,14 +290,14 @@
unset gem
$rvm_scripts_path/log "info" "$gem_name $gem_version exists, skipping (--force to re-install)"
else
if [[ -s "$gem" ]] ; then
cache_file="$gem"
- elif [[ -s "$rvm_ruby_gem_home/cache/${gem_file_name}" ]] ; then
- cache_file="$rvm_ruby_gem_home/cache/${gem_file_name}"
+ elif [[ -s "$(__rvm_current_gemcache_dir)/${gem_file_name}" ]] ; then
+ cache_file="$(__rvm_current_gemcache_dir)/${gem_file_name}"
else
- cache_file="${cache_file:-$(\ls ${rvm_ruby_gem_home}/cache/${gem_file_name} 2> /dev/null | sort | head -n1)}"
+ cache_file="${cache_file:-$(\ls "$(__rvm_current_gemcache_dir)/${gem_file_name}" 2> /dev/null | sort | head -n1)}"
fi
if [[ ! -s "$cache_file" ]] ; then
if [[ -s "$gem_file_name" ]] ; then
gem="$gem_file_name"
@@ -257,13 +312,13 @@
if [[ -z "$rvm_force_flag" ]] && [[ -s "${rvm_ruby_gem_home}/specifications/$(basename $gem_file_name)spec" ]] ; then
unset gem # already installed, not forcing reinstall.
$rvm_scripts_path/log "info" "$gem_name $gem_version exists, skipping (--force to re-install)"
else
- if [[ -s "$rvm_ruby_gem_home/cache/$(basename $gem_file_name)" ]] ; then
+ if [[ -s "$(__rvm_current_gemcache_dir)/$(basename $gem_file_name)" ]] ; then
mkdir -p "$rvm_tmp_path/$$/"
- mv "$rvm_ruby_gem_home/cache/$gem_file_name" "$rvm_tmp_path/$$/$gem_file_name"
+ mv "$(__rvm_current_gemcache_dir)/$gem_file_name" "$rvm_tmp_path/$$/$gem_file_name"
gem="$rvm_tmp_path/$$/$gem_file_name -f -l"
else
gem="$cache_file"
fi
fi
@@ -274,11 +329,10 @@
if [[ ! -z "$gem" ]] ; then
# TODO: Set vars if fourth field is non-empty (means that there are conditional statements to execute in the gem install line.
if [[ "rvm_make_flags_flag" -eq 1 ]] ; then __rvm_make_flags ; fi
if [[ ! -z "$rvm_ruby_gem_home" ]] && [[ "$rvm_ruby_gem_home" != "$rvm_gems_path" ]] ; then
- #command="GEM_HOME='$rvm_ruby_gem_home' GEM_PATH='$rvm_ruby_gem_home/bin:$rvm_gems_path/${rvm_ruby_string}${rvm_gemset_separator}global/bin' BUNDLE_PATH='${rvm_ruby_gem_home}' ${gem_prefix} gem install --ignore-dependencies $gems_args $rvm_gem_options $gem_postfix $vars"
command="GEM_HOME='$rvm_ruby_gem_home' GEM_PATH='$rvm_ruby_gem_home/bin:$rvm_gems_path/${rvm_ruby_string}${rvm_gemset_separator}global/bin' BUNDLE_PATH='${rvm_ruby_gem_home}' ${gem_prefix} gem install $gems_args $rvm_gem_options $gem_postfix $vars"
else
#--ignore-dependencies
command="$gem_prefix gem install --ignore-dependencies $gems_args $rvm_gem_options -q $gem $gem_postfix $vars"
fi
@@ -403,13 +457,17 @@
gemset_pristine $*
elif [[ "initial" = "$action" ]] ; then
gemset_initial
elif [[ "prune" = "$action" ]] ; then
gemset_prune
+elif [[ "update" = "$action" ]]; then
+ gemset_update
+elif [[ "globalcache" = "$action" ]]; then
+ gemset_globalcache $2
elif [[ "clear" = "$action" ]] ; then
$rvm_scripts_path/log "info" "gemset cleared."
exit 0
else
- $rvm_scripts_path/log "error" "Unrecognized gemset action '$action'.\n\nValid gems actions are: {import,export,create,copy,empty,delete,name,dir,list,gemdir,install,pristine,clear}"
+ usage
fi
exit $?