Permalink
Browse files

All rm -rf calls now use a _slightly_ safer __rvm_rm_rf with some san…

…ity checks in place. Thanks Sven!
  • Loading branch information...
1 parent 08f0b69 commit 651c1bd80bd5143691a10c2b0f9a487d69241ab5 @wayneeseguin wayneeseguin committed Feb 26, 2011
@@ -21,9 +21,7 @@ fi
builtin cd "$rvm_path/src"
-if [[ -d ./rvm ]] ; then
- rm -rf ./rvm/
-fi
+[[ -d "$PWD/.rvm/" ]] && "$PWD/.rvm"
git_url="git://github.com/wayneeseguin/rvm.git"
https_url="https://github.com/wayneeseguin/rvm.git"
@@ -189,7 +189,7 @@ __rvm_system_wide_permissions "$rvm_path"
mkdir -p "$rvm_path/src/"
builtin cd "$rvm_path/src"
-rm -rf ./rvm/
+[[ -d "$PWD/rvm/" ]] && rm -rf "$PWD/rvm/"
git clone --depth 1 git://github.com/wayneeseguin/rvm.git || git clone http://github.com/wayneeseguin/rvm.git
View
@@ -44,7 +44,7 @@ for script_name in initialize utility selector ; do
done
-for script_name in logging ; do
+for script_name in logging cleanup ; do
source "$rvm_scripts_path/functions/$script_name"
done
@@ -80,4 +80,4 @@ fi
export GEM_HOME GEM_PATH rvm_action rvm_alias_expanded rvm_archflags rvm_archive_extension rvm_bin_flag rvm_bin_path rvm_clang_flag rvm_configure_flags rvm_debug_flag rvm_default_flag rvm_delete_flag rvm_docs_type rvm_dump_environment_flag rvm_error_message rvm_expanding_aliases rvm_file_name rvm_gemdir_flag rvm_gemset_name rvm_gemstone_package_file rvm_gemstone_url rvm_head_flag rvm_hook rvm_install_arguments rvm_install_on_use_flag rvm_interactive_flag rvm_llvm_flag rvm_loaded_flag rvm_make_flags rvm_niceness rvm_nightly_flag rvm_only_path_flag rvm_parse_break rvm_patch_names rvm_patch_original_pwd rvm_pretty_print_flag rvm_prior_cc rvm_proxy rvm_quiet_flag rvm_ree_options rvm_reload_flag rvm_remove_flag rvm_ruby_alias rvm_ruby_aliases rvm_ruby_args rvm_ruby_binary rvm_ruby_bits rvm_ruby_configure rvm_ruby_file rvm_ruby_gem_home rvm_ruby_gem_path rvm_ruby_global_gems_path rvm_ruby_home rvm_ruby_interpreter rvm_ruby_irbrc rvm_ruby_load_path rvm_ruby_major_version rvm_ruby_make rvm_ruby_make_install rvm_ruby_minor_version rvm_ruby_mode rvm_ruby_name rvm_ruby_package_file rvm_ruby_package_name rvm_ruby_patch rvm_ruby_patch_level rvm_ruby_release_version rvm_ruby_repo_url rvm_ruby_require rvm_ruby_revision rvm_ruby_selected_flag rvm_ruby_sha rvm_ruby_string rvm_ruby_strings rvm_ruby_tag rvm_ruby_url rvm_ruby_user_tag rvm_ruby_version rvm_script_name rvm_sdk rvm_silent_flag rvm_sticky_flag rvm_system_flag rvm_token rvm_trace_flag rvm_use_flag rvm_user_flag rvm_verbose_flag rvm_wrapper_name
# Cleanup tmp on exit.
-trap "__rvm_cleanup_temp_for '$$'" 0 1 2 3 15
+trap "__rvm_cleanup_tmp '$$'" 0 1 2 3 15
View
@@ -20,7 +20,7 @@ return 0
cleanup()
{
- local cleanup_type current_path
+ local cleanup_type current_path entry
for cleanup_type in $1; do
@@ -30,7 +30,9 @@ cleanup()
rvm_log "Cleaning up rvm directory '$current_path'"
- rm -rf "$current_path"/* >/dev/null 2>&1
+ for entry in "$current_path"/* ; do
+ __rvm_rm_rf "$entry"
+ done
fi
View
@@ -78,7 +78,7 @@ generate_rdoc()
(
builtin cd "${rvm_src_path}/$rvm_docs_ruby_string/"
- \rm -rf "${rvm_docs_path:-"$rvm_path/docs"}/$rvm_docs_ruby_string/$rvm_docs_type/"
+ __rvm_rm_rf "${rvm_docs_path:-"$rvm_path/docs"}/$rvm_docs_ruby_string/$rvm_docs_type/"
rvm_log "Generating rdoc documentation, be aware that this could take a *long* time, and depends heavily on your system resources..."
View
@@ -0,0 +1,28 @@
+#!/usr/bin/env bash
+
+#
+# rm -rf with *some* safeguards in place.
+#
+__rvm_rm_rf()
+{
+ local result path="${1%%+(/|.)}"
+
+ case "${path}" in
+
+ (*(/|.)@(|/Applications|/Developer|/Guides|/Information|/Library|/Network|/System|/User|/Users|/Volumes|/backups|/bdsm|/bin|/boot|/cores|/data|/dev|/etc|/home|/lib|/lib64|/mach_kernel|/media|/misc|/mnt|/net|/opt|/private|/proc|/root|/sbin|/selinux|/srv|/sys|/tmp|/usr|/var))
+ result=1
+ ;;
+
+ *)
+ if [[ -n "${path}" && -d "${path}" ]] ; then
+ \rm -rf "${path}"
+ result=0
+ else
+ result=1
+ fi
+ ;
+ esac
+
+ reutrn $result
+}
+
View
@@ -132,7 +132,7 @@ gemset_globalcache()
case "${current_cache_path%\/}" in
*cache)
- rm -rf "$current_cache_path"
+ __rvm_rm_rf "$current_cache_path"
ln -nfs "$rvm_gems_cache_path" "$current_cache_path"
;;
esac
@@ -206,7 +206,7 @@ gemset_create()
mv "$gem_home/cache"/*.gem "$rvm_gems_cache_path/" 2>/dev/null
- rm -rf "$gem_home/cache"
+ __rvm_rm_rf "$gem_home/cache"
fi
ln -nfs "$rvm_gems_cache_path" "$gem_home/cache"
@@ -273,7 +273,7 @@ gemset_delete()
if [[ -d "$gemdir" && "$gemdir" != '/' && ${rvm_force_flag:-0} -gt 0 ]] ; then
- rm -rf "$gemdir"
+ __rvm_rm_rf "$gemdir"
elif [[ -d "$gemdir" ]] ; then
@@ -289,7 +289,7 @@ gemset_delete()
rm -f "$gemdir/cache"
fi
- rm -rf "$gemdir"
+ __rvm_rm_rf "$gemdir"
else
rvm_log "Not doing anything, phew... close call that one eh?"
@@ -309,15 +309,17 @@ gemset_delete()
gemset_empty()
{
- local gemdir
+ local gemdir entry
if [[ -z "${rvm_ruby_gem_home:-""}" ]] ; then __rvm_select ; fi
gemdir="$rvm_ruby_gem_home"
- if [[ -d "$gemdir" && "$gemdir" != '/' && ${rvm_force_flag:-0} -gt 0 ]] ; then
+ if [[ ${rvm_force_flag:-0} -gt 0 ]] ; then
- builtin cd "$gemdir" && rm -rf ./bin/* ./doc/* ./gems/* ./specifications/*
+ for entry in "$gemdir"/bin/* "$gemdir"/doc/* "$gemdir"/gems/* "$gemdir"/specifications/* ; done
+ __rvm_rm_rf "$entry"
+ done
elif [[ -d "$gemdir" ]] ; then
@@ -329,7 +331,9 @@ gemset_empty()
if [[ "yes" = "$response" ]] ; then
- builtin cd "$gemdir" && rm -rf ./bin/* ./doc/* ./gems/* ./specifications/*
+ for entry in "$gemdir"/bin/* "$gemdir"/doc/* "$gemdir"/gems/* "$gemdir"/specifications/* ; done
+ __rvm_rm_rf "$entry"
+ done
else
rvm_log "Not doing anything, phew... close call that one eh?"
@@ -854,7 +858,7 @@ gemset_prune()
rvm_log "Removing live cache and restoring temporary cache..."
# Switch the cache back.
- rm -rf "$live_cache_path"
+ __rvm_rm_rf "$live_cache_path"
mv "$temporary_cache_path" "$live_cache_path"
View
@@ -606,7 +606,7 @@ if [[ -s "$rvm_config_path/default" ]]; then
fi ; unset original_version
- rm -rf "$rvm_config_path/default"
+ __rvm_rm_rf "$rvm_config_path/default"
fi
Oops, something went wrong.

0 comments on commit 651c1bd

Please sign in to comment.