[Qa-jenkins-scm] [jenkins.debian.net] 02/03: schroot-create: enable the cleanup trap earlier in the process, so there we won't leave temp files around if we fail mid-way

Mattia Rizzolo mattia at debian.org
Thu Apr 5 15:23:08 UTC 2018


This is an automated email from the git hooks/post-receive script.

mattia pushed a commit to branch master
in repository jenkins.debian.net.

commit a21e021f0f2ea5e3012aa3b2b1f36441a9753ea9
Author: Mattia Rizzolo <mattia at debian.org>
Date:   Thu Apr 5 17:19:12 2018 +0200

    schroot-create: enable the cleanup trap earlier in the process, so there we won't leave temp files around if we fail mid-way
    
    Signed-off-by: Mattia Rizzolo <mattia at debian.org>
---
 bin/schroot-create.sh | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/bin/schroot-create.sh b/bin/schroot-create.sh
index 57b0561..89855f5 100755
--- a/bin/schroot-create.sh
+++ b/bin/schroot-create.sh
@@ -54,7 +54,22 @@ shift
 SUITE="$1"
 shift
 
+SCHROOT_TARGET=$(mktemp -d -p $SCHROOT_BASE/ schroot-install-$TARGET-XXXX)
+if [ -z "$SCHROOT_TARGET" ]; then
+	echo "Could not create a directory to create the chroot in, aborting."
+	exit 1
+fi
 TMPLOG=$(mktemp --tmpdir=$TMPDIR schroot-create-XXXXXXXX)
+cleanup() {
+	cd
+	if [ -d "$SCHROOT_TARGET" ]; then
+		sudo rm -rf --one-file-system "$SCHROOT_TARGET" || ( echo "Warning: $SCHROOT_TARGET could not be fully removed during cleanup." ; ls "$SCHROOT_TARGET" -la )
+	fi
+	rm -f "$TMPLOG"
+}
+trap cleanup INT TERM EXIT
+
+sudo chmod +x $SCHROOT_TARGET	# workaround #844220 / #872812
 
 if [ "$SUITE" = "experimental" ] ; then
 	# experimental cannot be bootstrapped
@@ -66,12 +81,6 @@ elif [ "$SUITE" != "unstable" ] && [ "$SUITE" != "sid" ] ; then
 	EXTRA_SOURCES[7]="deb-src http://security.debian.org $SUITE/updates main $CONTRIB"
 fi
 
-export SCHROOT_TARGET=$(mktemp -d -p $SCHROOT_BASE/ schroot-install-$TARGET-XXXX)
-if [ -z "$SCHROOT_TARGET" ]; then
-	echo "Could not create a directory to create the chroot in, aborting."
-	exit 1
-fi
-sudo chmod +x $SCHROOT_TARGET	# workaround #844220 / #872812
 
 robust_chroot_apt() {
 	set +e
@@ -181,14 +190,6 @@ bootstrap() {
 	fi
 }
 
-cleanup() {
-	cd
-	if [ -d "$SCHROOT_TARGET" ]; then
-		sudo rm -rf --one-file-system "$SCHROOT_TARGET" || ( echo "Warning: $SCHROOT_TARGET could not be fully removed during cleanup." ; ls "$SCHROOT_TARGET" -la )
-	fi
-	rm -f "$TMPLOG"
-}
-trap cleanup INT TERM EXIT
 bootstrap $@
 
 trap - INT TERM EXIT

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/qa/jenkins.debian.net.git



More information about the Qa-jenkins-scm mailing list