From 0d7a05157e90748b909e91b054836bd2baad666e Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Mon, 4 Feb 2013 23:43:38 +0100 Subject: [PATCH] Autoclean on unsuccessful installation --- bin/rbenv-install | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bin/rbenv-install b/bin/rbenv-install index f48e188d..481e8bd4 100755 --- a/bin/rbenv-install +++ b/bin/rbenv-install @@ -135,6 +135,13 @@ fi # Execute `before_install` hooks. for hook in "${before_hooks[@]}"; do eval "$hook"; done +# Plan cleanup on unsuccessful installation. +cleanup() { + rm -rf "$PREFIX" +} + +trap cleanup SIGINT + # Invoke `ruby-build` and record the exit status in $STATUS. Run # `rbenv rehash` after a successful installation. STATUS=0 @@ -144,6 +151,10 @@ ruby-build $KEEP $VERBOSE "$DEFINITION" "$PREFIX" || STATUS="$?" for hook in "${after_hooks[@]}"; do eval "$hook"; done # Run `rbenv-rehash` after a successful installation. -[ "$STATUS" != "0" ] || rbenv rehash +if [ "$STATUS" == "0" ]; then + rbenv rehash +else + cleanup +fi exit "$STATUS"