Skip to content

Commit

Permalink
split __rvm_package into smaller functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mpapis committed Jan 24, 2013
1 parent 06f7d2e commit 3f7d808
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 39 deletions.
8 changes: 4 additions & 4 deletions scripts/external
Expand Up @@ -271,10 +271,10 @@ external_import_validate_archive()
typeset -a downloaded_names path_to_bin_ruby typeset -a downloaded_names path_to_bin_ruby


__rvm_read_lines path_to_bin_ruby < <( __rvm_read_lines path_to_bin_ruby < <(
__rvm_package list "$rvm_archives_path/${rvm_ruby_package_file}" | grep "bin/ruby$" __rvm_package_list "$rvm_archives_path/${rvm_ruby_package_file}" | grep "bin/ruby$"
) )
__rvm_read_lines downloaded_names < <( __rvm_read_lines downloaded_names < <(
__rvm_package list "$rvm_archives_path/${rvm_ruby_package_file}" | awk -F/ '{print $1}' | sort -u __rvm_package_list "$rvm_archives_path/${rvm_ruby_package_file}" | awk -F/ '{print $1}' | sort -u
) )
if if
[[ "${#path_to_bin_ruby[*]}" -eq 1 ]] [[ "${#path_to_bin_ruby[*]}" -eq 1 ]]
Expand All @@ -298,7 +298,7 @@ external_import_extract()
{ {
rm -rf "${rvm_rubies_path}/${rvm_ruby_string}" rm -rf "${rvm_rubies_path}/${rvm_ruby_string}"
mkdir -p "${rvm_rubies_path}/${rvm_ruby_string}" mkdir -p "${rvm_rubies_path}/${rvm_ruby_string}"
__rvm_package extract "$rvm_archives_path/${rvm_ruby_package_file}" "${rvm_rubies_path}/${rvm_ruby_string}" || { __rvm_package_extract "$rvm_archives_path/${rvm_ruby_package_file}" "${rvm_rubies_path}/${rvm_ruby_string}" || {
$err_command "Unpacking ${rvm_ruby_package_file} failed." $err_command "Unpacking ${rvm_ruby_package_file} failed."
return 6 return 6
} }
Expand Down Expand Up @@ -450,7 +450,7 @@ external_prepare_package()


rvm_log "Preparing ${rvm_ruby_string} ..." rvm_log "Preparing ${rvm_ruby_string} ..."
if if
__rvm_package create "${file_name}" "${rvm_rubies_path}" "${rvm_ruby_string}" __rvm_package_create "${file_name}" "${rvm_rubies_path}" "${rvm_ruby_string}"
then then
rvm_log "Prepared ${file_name}." rvm_log "Prepared ${file_name}."
else else
Expand Down
2 changes: 1 addition & 1 deletion scripts/functions/manage/base
Expand Up @@ -583,7 +583,7 @@ __rvm_fetch_ruby()
mkdir -p "${rvm_tmp_path:-/tmp}/rvm_src_$$" mkdir -p "${rvm_tmp_path:-/tmp}/rvm_src_$$"


__rvm_log_command "extract" "$rvm_ruby_string - #extracting $rvm_ruby_package_file to ${rvm_src_path}/$rvm_ruby_string" \ __rvm_log_command "extract" "$rvm_ruby_string - #extracting $rvm_ruby_package_file to ${rvm_src_path}/$rvm_ruby_string" \
__rvm_package extract "${rvm_archives_path}/$rvm_ruby_package_file.$rvm_archive_extension" "${rvm_tmp_path:-/tmp}/rvm_src_$$" || __rvm_package_extract "${rvm_archives_path}/$rvm_ruby_package_file.$rvm_archive_extension" "${rvm_tmp_path:-/tmp}/rvm_src_$$" ||
case $? in case $? in
199) 199)
rvm_error "\nUnrecognized archive format '$archive_format'" rvm_error "\nUnrecognized archive format '$archive_format'"
Expand Down
2 changes: 1 addition & 1 deletion scripts/functions/manage/ironruby
Expand Up @@ -65,7 +65,7 @@ ironruby_install()
mkdir -p "${rvm_src_path}/$rvm_ruby_string" "$rvm_ruby_home" mkdir -p "${rvm_src_path}/$rvm_ruby_string" "$rvm_ruby_home"


__rvm_log_command "extract" "$rvm_ruby_string - #extracting $rvm_ruby_package_file to ${rvm_src_path}/$rvm_ruby_string" \ __rvm_log_command "extract" "$rvm_ruby_string - #extracting $rvm_ruby_package_file to ${rvm_src_path}/$rvm_ruby_string" \
__rvm_package extract "${rvm_archives_path}/${rvm_ruby_package_file}" "${rvm_src_path}/$rvm_ruby_string" || __rvm_package_extract "${rvm_archives_path}/${rvm_ruby_package_file}" "${rvm_src_path}/$rvm_ruby_string" ||
case $? in case $? in
199) 199)
rvm_error "\nUnrecognized archive format '$archive_format'" rvm_error "\nUnrecognized archive format '$archive_format'"
Expand Down
2 changes: 1 addition & 1 deletion scripts/functions/manage/maglev
Expand Up @@ -72,7 +72,7 @@ maglev_install()
fi fi


__rvm_log_command "extract" "$rvm_ruby_string - #extracting $rvm_gemstone_package_file to ${rvm_src_path}" \ __rvm_log_command "extract" "$rvm_ruby_string - #extracting $rvm_gemstone_package_file to ${rvm_src_path}" \
__rvm_package extract "${rvm_archives_path}/$rvm_gemstone_package_file.$rvm_archive_extension" "${rvm_src_path}" || __rvm_package_extract "${rvm_archives_path}/$rvm_gemstone_package_file.$rvm_archive_extension" "${rvm_src_path}" ||
case $? in case $? in
199) 199)
rvm_error "\nUnrecognized archive format '$archive_format'" rvm_error "\nUnrecognized archive format '$archive_format'"
Expand Down
2 changes: 1 addition & 1 deletion scripts/functions/manage/ree
Expand Up @@ -39,7 +39,7 @@ ree_install()
fi fi


__rvm_log_command "extract" "$rvm_ruby_string - #extracting $rvm_ruby_package_file to ${rvm_src_path}/$rvm_ruby_string" \ __rvm_log_command "extract" "$rvm_ruby_string - #extracting $rvm_ruby_package_file to ${rvm_src_path}/$rvm_ruby_string" \
__rvm_package extract "${rvm_archives_path}/$rvm_ruby_package_file.$rvm_archive_extension" "${rvm_src_path}/" || __rvm_package_extract "${rvm_archives_path}/$rvm_ruby_package_file.$rvm_archive_extension" "${rvm_src_path}/" ||
case $? in case $? in
199) 199)
rvm_error "\nUnrecognized archive format '$archive_format'" rvm_error "\nUnrecognized archive format '$archive_format'"
Expand Down
2 changes: 1 addition & 1 deletion scripts/functions/manage/rubinius
Expand Up @@ -104,7 +104,7 @@ rubinius_install()
fi fi


__rvm_log_command "extract" "$rvm_ruby_string - #extracting $rvm_ruby_package_file to ${rvm_src_path}/$rvm_ruby_string" \ __rvm_log_command "extract" "$rvm_ruby_string - #extracting $rvm_ruby_package_file to ${rvm_src_path}/$rvm_ruby_string" \
__rvm_package extract "${rvm_archives_path}/$rvm_ruby_package_file" "${rvm_tmp_path:-/tmp}/rvm_src_$$" || __rvm_package_extract "${rvm_archives_path}/$rvm_ruby_package_file" "${rvm_tmp_path:-/tmp}/rvm_src_$$" ||
case $? in case $? in
199) 199)
rvm_error "\nUnrecognized archive format '$archive_format'" rvm_error "\nUnrecognized archive format '$archive_format'"
Expand Down
2 changes: 1 addition & 1 deletion scripts/functions/pkg
Expand Up @@ -10,7 +10,7 @@ install_package()


"$rvm_scripts_path/fetch" "$package_url/$package-$version.$archive_format" || return $? "$rvm_scripts_path/fetch" "$package_url/$package-$version.$archive_format" || return $?
__rvm_log_command "$package/extract" "Extracting ${package} to $rvm_src_path/$package-$version" \ __rvm_log_command "$package/extract" "Extracting ${package} to $rvm_src_path/$package-$version" \
__rvm_package extract "$rvm_archives_path/$package-$version.$archive_format" "$rvm_src_path" || __rvm_package_extract "$rvm_archives_path/$package-$version.$archive_format" "$rvm_src_path" ||
case $? in case $? in
199) 199)
rvm_error "\nUnrecognized archive format '$archive_format'" rvm_error "\nUnrecognized archive format '$archive_format'"
Expand Down
76 changes: 48 additions & 28 deletions scripts/functions/utility
Expand Up @@ -732,43 +732,63 @@ __rvm_fix_group_permissions()
fi fi
} }


# params: action archive_file [path [path2]] # params: archive_file
__rvm_package() __rvm_package_list()
{ {
rvm_debug __rvm_package:$#: "$@" rvm_debug __rvm_package_list:$#: "$@"
case "$1-$2" in case "$1" in
list-*.zip) *.zip)
unzip -Z -1 "$2" unzip -Z -1 "$1"
;; ;;
extract-*.zip) *.tar.bz2)
[[ -d "$3" ]] || mkdir -p "$3" ${rvm_tar_command:-tar} tjf "$1"
unzip -q -o "$2" -d "$3"
;; ;;
list-*.tar.bz2) *.tar.gz|list-*.tgz)
${rvm_tar_command:-tar} tjf "$2" ${rvm_tar_command:-tar} tzf "$1"
;; ;;
create-*.tar.bz2) *)
if [[ -z "${4:-}" ]] return 199
then ${rvm_tar_command:-tar} cjf "$2" "$3" ;;
else ${rvm_tar_command:-tar} cjf "$2" -C "$3" "$4" esac
fi }

# params: archive_file [path]
__rvm_package_extract()
{
rvm_debug __rvm_package_extract:$#: "$@"
[[ -d "$2" ]] || mkdir -p "$2"
case "$1" in
*.zip)
unzip -q -o "$1" -d "$2"
;; ;;
extract-*.tar.bz2) *.tar.bz2)
[[ -d "$3" ]] || mkdir -p "$3" ${rvm_tar_command:-tar} xjf "$1" -C "$2" ${rvm_tar_options:-}
${rvm_tar_command:-tar} xjf "$2" -C "$3" ${rvm_tar_options:-}
;; ;;
list-*.tar.gz|list-*.tgz) *.tar.gz|extract-*.tgz)
${rvm_tar_command:-tar} tzf "$2" ${rvm_tar_command:-tar} xzf "$1" -C "$2" ${rvm_tar_options:-}
;; ;;
create-*.tar.gz|create-*.tgz) *)
if [[ -z "${4:-}" ]] return 199
then ${rvm_tar_command:-tar} czf "$2" "$3" ;;
else ${rvm_tar_command:-tar} czf "$2" -C "$3" "$4" esac
}

# params: archive_file [path [path2]]
__rvm_package_create()
{
rvm_debug __rvm_package_create:$#: "$@"
case "$1" in
*.tar.bz2)
if [[ -z "${3:-}" ]]
then ${rvm_tar_command:-tar} cjf "$1" "$2"
else ${rvm_tar_command:-tar} cjf "$1" -C "$2" "$3"
fi fi
;; ;;
extract-*.tar.gz|extract-*.tgz) *.tar.gz|create-*.tgz)
[[ -d "$3" ]] || mkdir -p "$3" if [[ -z "${3:-}" ]]
${rvm_tar_command:-tar} xzf "$2" -C "$3" ${rvm_tar_options:-} then ${rvm_tar_command:-tar} czf "$1" "$2"
else ${rvm_tar_command:-tar} czf "$1" -C "$2" "$3"
fi
;; ;;
*) *)
return 199 return 199
Expand Down
2 changes: 1 addition & 1 deletion scripts/rubygems
Expand Up @@ -183,7 +183,7 @@ rubygems_setup()
\mkdir -p "${rvm_src_path}/$rvm_gem_package_name" \mkdir -p "${rvm_src_path}/$rvm_gem_package_name"


__rvm_log_command "rubygems.extract" "Extracting $rvm_gem_package_name ..." \ __rvm_log_command "rubygems.extract" "Extracting $rvm_gem_package_name ..." \
__rvm_package extract "${rvm_archives_path}/$rvm_gem_package_name.tgz" "${rvm_src_path}" __rvm_package_extract "${rvm_archives_path}/$rvm_gem_package_name.tgz" "${rvm_src_path}"
fi fi


rubygems_remove # Remove old gems. rubygems_remove # Remove old gems.
Expand Down

0 comments on commit 3f7d808

Please sign in to comment.