cleanup 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env bash
  2. # wrapper for smaller output from __rvm_log_command
  3. __rvm_rm_rf()
  4. {
  5. __rvm_rm_rf_verbose "$@"
  6. }
  7. #
  8. # \command \rm -rf with *some* safeguards in place.
  9. #
  10. __rvm_rm_rf_verbose()
  11. {
  12. \typeset target
  13. target="${1%%+(/|.)}"
  14. #NOTE: RVM Requires extended globbing shell feature turned on.
  15. if
  16. [[ -n "${ZSH_VERSION:-}" ]]
  17. then
  18. \builtin setopt extendedglob
  19. elif
  20. [[ -n "${BASH_VERSION:-}" ]]
  21. then
  22. \builtin shopt -s extglob
  23. else
  24. rvm_error "What the heck kind of shell are you running here???"
  25. fi
  26. case "${target}" in
  27. (*(/|.)@(|/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))
  28. rvm_debug "__rvm_rm_rf target is not valid - can not remove"
  29. return 1
  30. ;;
  31. (*)
  32. if
  33. [[ -z "${target}" ]]
  34. then
  35. rvm_debug "__rvm_rm_rf target not given"
  36. return 1
  37. elif
  38. [[ -d "${target}" ]] # directory
  39. then
  40. \command \rm -rf "${target}" ||
  41. {
  42. \typeset ret=$?
  43. rvm_debug "__rvm_rm_rf error removing target dir '${target}'."
  44. return $ret
  45. }
  46. elif
  47. [[ -f "${target}" || -L "${target}" ]] # file / broken symbolic link
  48. then
  49. \command \rm -f "${target}" ||
  50. {
  51. \typeset ret=$?
  52. rvm_debug "__rvm_rm_rf error removing target file/link '${target}'."
  53. return $ret
  54. }
  55. else
  56. rvm_debug "__rvm_rm_rf already gone: $*"
  57. fi
  58. ;;
  59. esac
  60. true # for OSX
  61. }
  62. # Cleans up temp folders for a given prefix ($1),
  63. # or the current process id.
  64. __rvm_cleanup_tmp()
  65. {
  66. if
  67. [[ -d "${rvm_tmp_path}/" ]]
  68. then
  69. case "${rvm_tmp_path%\/}" in
  70. *tmp)
  71. __rvm_rm_rf "${rvm_tmp_path}/${1:-$$}*"
  72. ;;
  73. esac
  74. fi
  75. true # for osx
  76. }