Skip to content
This repository
Browse code

update gemset delete, rewrite --default to use aliases, update alias …

…to handle default, fix #492
  • Loading branch information...
commit 4f317721ec2515685261e2a08d43116e2dfabfe8 1 parent 619c8d9
Michal Papis authored October 14, 2011
84  scripts/alias
@@ -70,8 +70,37 @@ alias_show() {
70 70
   fi
71 71
 }
72 72
 
  73
+alias_after_delete_default()
  74
+{
  75
+  rvm_log "Deleting default links/files"
  76
+
  77
+  for _path in $rvm_bin_path/default_* "$rvm_environments_path/default" "$rvm_wrappers_path/default"
  78
+  do
  79
+    [[ -f "$_path" ]] && rm -rf ${_path}
  80
+  done
  81
+
  82
+  for wrapper in "$rvm_path"/wrappers/default/*
  83
+  do
  84
+    wrapper="${wrapper##*\/}"
  85
+
  86
+    if [[ -L "$rvm_bin_path/${wrapper}" ]]
  87
+    then
  88
+      rm -f "$rvm_bin_path/${wrapper}"
  89
+    fi
  90
+
  91
+    rm -f "$rvm_bin_path/${wrapper}"
  92
+
  93
+    # If the RVM bin path is different from rvm_path/bin, ensure they are
  94
+    # in sync.
  95
+    if [[ "${rvm_bin_path}" != "${rvm_path}/bin" ]]
  96
+    then
  97
+      rm -f "${rvm_path}/bin/${wrapper}"
  98
+    fi
  99
+  done
  100
+}
  101
+
73 102
 alias_delete() {
74  
-  echo "Deleting alias: $alias_name"
  103
+  rvm_log "Deleting alias: $alias_name"
75 104
 
76 105
   for link in "$rvm_rubies_path/$alias_name" ; do
77 106
     if [[ -L "$link" ]] ; then rm -f $link ; fi
@@ -80,6 +109,55 @@ alias_delete() {
80 109
   [[ -s "$rvm_path/config/alias" ]] || return 0
81 110
 
82 111
   "$rvm_scripts_path"/db "$rvm_path/config/alias" "$alias_name" "delete"
  112
+
  113
+  if [[ "default" == "$alias_name" ]] ; then
  114
+    alias_after_delete_default
  115
+  fi
  116
+}
  117
+
  118
+alias_after_create_default()
  119
+{
  120
+  rvm_log "Creating default links/files"
  121
+
  122
+  environment_id="${final_environment_identifier}"
  123
+
  124
+  if (( ${rvm_user_install_flag:=0} == 0 ))
  125
+  then
  126
+    # Sets up the default wrappers.
  127
+    "$rvm_scripts_path/wrapper" "$rvm_ruby_string" --no-prefix
  128
+  else
  129
+    "$rvm_scripts_path/wrapper" "$rvm_ruby_string" "default"
  130
+  fi
  131
+
  132
+  RUBY_VERSION="$("$rvm_ruby_home/bin/ruby" -v | \sed 's#^\(.*\) (.*$#\1#')"
  133
+
  134
+  export GEM_HOME GEM_PATH MY_RUBY_HOME RUBY_VERSION
  135
+
  136
+  for _path in "$rvm_environments_path" "$rvm_wrappers_path"
  137
+  do
  138
+    # Remove old default if it exists.
  139
+    [[ -L "$_path/default" ]] && rm -f "$_path/default"
  140
+    # Symlink n the new default
  141
+    \ln -fs "$_path/$environment_id" "$_path/default"
  142
+  done
  143
+
  144
+  # Copy wrapper scripts for the newly set default to the RVM bin path.
  145
+  for wrapper in "$rvm_path"/wrappers/default/*
  146
+  do
  147
+    if [[ -L "$rvm_bin_path/${wrapper##*\/}" ]]
  148
+    then
  149
+      rm -f "$rvm_bin_path/${wrapper##*\/}"
  150
+    fi
  151
+
  152
+    cp -f "$wrapper" "$rvm_bin_path/${wrapper##*\/}"
  153
+
  154
+    # If the RVM bin path is different from rvm_path/bin, ensure they are
  155
+    # in sync.
  156
+    if [[ "${rvm_bin_path}" != "${rvm_path}/bin" ]]
  157
+    then
  158
+      cp -f "${wrapper}" "${rvm_path}/bin/"
  159
+    fi
  160
+  done
83 161
 }
84 162
 
85 163
 alias_create() {
@@ -141,6 +219,10 @@ alias_create() {
141 219
 
142 220
       "$rvm_scripts_path"/db "$rvm_path/config/alias" "$alias_name" "$final_environment_identifier"
143 221
 
  222
+      if [[ "default" == "$alias_name" ]] ; then
  223
+        alias_after_create_default
  224
+      fi
  225
+
144 226
     else
145 227
 
146 228
       if [[ -d "$rvm_rubies_path/$alias_name" ]] ; then
30  scripts/gemsets
@@ -236,6 +236,25 @@ gemset_list()
236 236
   return 0
237 237
 }
238 238
 
  239
+gemset_after_delete_cleanup()
  240
+{
  241
+  rvm_gemset_name=$1
  242
+  ruby_at_gemset=$2
  243
+  gemdir=$3
  244
+
  245
+  if [[ -L "$gemdir/cache" ]]
  246
+  then
  247
+    rm -f "$gemdir/cache"
  248
+  fi
  249
+
  250
+  (
  251
+    for item in $( $rvm_scripts_path/alias search_by_target ${ruby_at_gemset} )
  252
+    do
  253
+      $rvm_scripts_path/alias delete ${item}
  254
+    done
  255
+  )
  256
+}
  257
+
239 258
 gemset_delete()
240 259
 {
241 260
   gemsets=(${args[@]})
@@ -252,10 +271,13 @@ gemset_delete()
252 271
 
253 272
   if [[ -n "$rvm_gemset_name" ]]
254 273
   then
255  
-    gemdir="${rvm_gems_path:-"$rvm_path/gems"}/$rvm_ruby_string${rvm_gemset_separator:-"@"}$rvm_gemset_name"
  274
+    ruby_at_gemset="$rvm_ruby_string${rvm_gemset_separator:-"@"}$rvm_gemset_name"
  275
+    gemdir="${rvm_gems_path:-"$rvm_path/gems"}/${ruby_at_gemset}"
  276
+
256 277
     if [[ -d "$gemdir" && "$gemdir" != '/' && ${rvm_force_flag:-0} -gt 0 ]]
257 278
     then
258 279
       __rvm_rm_rf "$gemdir"
  280
+      gemset_after_delete_cleanup $rvm_gemset_name $ruby_at_gemset $gemdir
259 281
 
260 282
     elif [[ -d "$gemdir" ]]
261 283
     then
@@ -266,11 +288,9 @@ gemset_delete()
266 288
 
267 289
       if [[ "yes" == "$response" ]]
268 290
       then
269  
-        if [[ -L "$gemdir/cache" ]]
270  
-        then
271  
-          rm -f "$gemdir/cache"
272  
-        fi
273 291
         __rvm_rm_rf "$gemdir"
  292
+        gemset_after_delete_cleanup $rvm_gemset_name $ruby_at_gemset $gemdir
  293
+
274 294
       else
275 295
         rvm_log "Not doing anything, phew... close call that one eh?"
276 296
       fi
50  scripts/selector
@@ -500,52 +500,12 @@ __rvm_use()
500 500
     local environment_id="$(__rvm_env_string)"
501 501
 
502 502
     if (( ${rvm_default_flag:=0} == 1 )) &&
503  
-      [[ "default" != "${rvm_ruby_interpreter:-""}" ]]
  503
+      [[ "default" != "${rvm_ruby_interpreter:-}" ]] &&
  504
+      [[ "system"  != "${rvm_ruby_interpreter:-}" ]]
504 505
     then
505  
-      if (( ${rvm_user_install_flag:=0} == 0 ))
506  
-      then
507  
-        # Sets up the default wrappers.
508  
-        "$rvm_scripts_path/wrapper" "$rvm_ruby_string" --no-prefix
509  
-      else
510  
-        "$rvm_scripts_path/wrapper" "$rvm_ruby_string" "default"
511  
-      fi
512  
-
513  
-      if [[ "system" != "$rvm_ruby_interpreter" ]]
514  
-      then
515  
-        RUBY_VERSION="$("$rvm_ruby_home/bin/ruby" -v | \sed 's#^\(.*\) (.*$#\1#')"
516  
-
517  
-        export GEM_HOME GEM_PATH MY_RUBY_HOME RUBY_VERSION
518  
-
519  
-        # Switch the default alias to the new environment id
520  
-        "$rvm_scripts_path/alias" delete default &> /dev/null
521  
-        "$rvm_scripts_path/alias" create default "$environment_id" >& /dev/null
522  
-
523  
-        for _path in "$rvm_environments_path" "$rvm_wrappers_path"
524  
-        do
525  
-          # Remove old default if it exists.
526  
-          [[ -L "$_path/default" ]] && rm -f "$_path/default"
527  
-          # Symlink n the new default
528  
-          \ln -fs "$_path/$environment_id" "$_path/default"
529  
-        done
530  
-
531  
-        # Copy wrapper scripts for the newly set default to the RVM bin path.
532  
-        for wrapper in "$rvm_path"/wrappers/default/*
533  
-        do
534  
-          if [[ -L "$rvm_bin_path/${wrapper##*\/}" ]]
535  
-          then
536  
-            rm -f "$rvm_bin_path/${wrapper##*\/}"
537  
-          fi
538  
-
539  
-          cp -f "$wrapper" "$rvm_bin_path/${wrapper##*\/}"
540  
-
541  
-          # If the RVM bin path is different from rvm_path/bin, ensure they are
542  
-          # in sync.
543  
-          if [[ "${rvm_bin_path}" != "${rvm_path}/bin" ]]
544  
-          then
545  
-            cp -f "${wrapper}" "${rvm_path}/bin/"
546  
-          fi
547  
-        done
548  
-      fi
  506
+      # Switch the default alias to the new environment id
  507
+      "$rvm_scripts_path/alias" delete default &> /dev/null
  508
+      "$rvm_scripts_path/alias" create default "$environment_id" >& /dev/null
549 509
     fi
550 510
 
551 511
     rvm_default_flag=0

0 notes on commit 4f31772

Please sign in to comment.
Something went wrong with that request. Please try again.