scripts/repair in rvm-1.0.11 vs scripts/repair in rvm-1.0.13

- old
+ new

@@ -1,27 +1,56 @@ #!/usr/bin/env bash source "$rvm_path/scripts/base" -usage() { +usage() +{ printf " Usage: rvm repair [option] Options: wrappers - Repair wrappers symlinks - Repair symlinks environments - Repair environments archives - Repair archives + gemsets - Repair gemsets all - Repair all of the above " } -repair_wrappers() { +repair_gemsets() +{ + local directory directories + "$rvm_path/scripts/log" "info" \ + "Removing gemsets missing names or interpreters." + + ( + builtin cd "${rvm_gems_path:-"rvm_path/gems"}" + + directories=( + $( find . -mindepth 1 -maxdepth 1 -type d | grep '@$' ) + $( find . -mindepth 1 -maxdepth 1 -type d | grep '^./@') + ) + + for directory in "${directories[@]//.\/}" ; do + + rm -rf "./$directory/" + + done + ) + + "$rvm_path/scripts/log" "info" "Gemsets repaired." + + return 0 +} + +repair_wrappers() +{ local wrapper_ruby_name "$rvm_path/scripts/log" "info" "Regenerating all wrappers..." while read -r wrapper_ruby_name ; do @@ -34,24 +63,28 @@ done < <("$rvm_path/scripts/list" gemsets strings) "$rvm_path/scripts/log" "info" "Wrappers regenerated" + return 0 } # Removes stale symlinks in $rvm_bin_path, likely # related to wrappers. -repair_symlinks() { - +repair_symlinks() +{ "$rvm_path/scripts/log" "info" "Repairing symlinks..." ( builtin cd "${rvm_bin_path:-"$rvm_path/bin"}" for executable_name in $(\find \. -type l); do - [[ -e "$executable_name" || "$(readlink "$executable_name")" != "$rvm_path/wrappers/"* ]] && continue + if [[ -e "$executable_name" \ + || "$(readlink "$executable_name")" != "$rvm_path/wrappers/"* ]] ; then + continue + fi if [[ -f "$executable_name" ]] ; then "$rvm_path/scripts/log" "info" \ "removing stale symlink from $(basename "$executable_name")" @@ -64,16 +97,17 @@ "$rvm_path/scripts/log" "info" "Symlinks repaired" } # Regenerates each symlink file. -repair_environments() { +repair_environments() +{ local environment_name environments "$rvm_path/scripts/log" "info" "Regenerating environments..." - environments=($(cd "$rvm_path/environments" ; find . -maxdepth 1 -mindepth 1 -type f)) + environments=($(builtin cd "$rvm_path/environments" ; find . -maxdepth 1 -mindepth 1 -type f)) for environment_name in "${environments[@]//.\/}" ; do [[ -L "$rvm_path/environments/$environment_name" ]] && continue @@ -96,16 +130,17 @@ return 0 } # Removes archives that have incorrect md5 sums. -repair_archives() { - +repair_archives() +{ local archive_file archives stored_md5sum + "$rvm_path/scripts/log" "info" "Repairing archives..." - archives=($(cd "${rvm_archives_path:-"$rvm_path/archives"}" ; find . -maxdepth 1 -mindepth 1 -type f)) + archives=($(builtin cd "${rvm_archives_path:-"$rvm_path/archives"}" ; find . -maxdepth 1 -mindepth 1 -type f)) for archive_file in "${archives[@]//.\/}" ; do [[ -f "${rvm_archives_path:-"$rvm_path/archives"}/$archive_file" ]] || continue @@ -125,12 +160,12 @@ "$rvm_path/scripts/log" "info" "Archives repaired" return 0 } -repair_all() { - +repair_all() +{ repair_symlinks repair_archives repair_environments @@ -151,9 +186,10 @@ fi case "$action" in all) repair_all ;; symlinks) repair_symlinks ;; + gemsets) repair_gemsets ;; environments) repair_environments ;; archives) repair_archives ;; wrappers) repair_wrappers ;; help) usage ;; *) usage >&2 ; exit 1 ;;