[X2Go-Commits] [buildscripts] 04/14: bin/build-deb-package: add cleanup function to not leave random temporary directories around.

git-admin at x2go.org git-admin at x2go.org
Fri Apr 3 03:07:47 CEST 2015


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

x2go pushed a commit to branch master
in repository buildscripts.

commit 6bc245d846cd4c50609c1439121f202fc037365d
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Fri Apr 3 02:32:25 2015 +0200

    bin/build-deb-package: add cleanup function to not leave random temporary directories around.
---
 bin/build-deb-package |   25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/bin/build-deb-package b/bin/build-deb-package
index b5f63ff..6f25293 100755
--- a/bin/build-deb-package
+++ b/bin/build-deb-package
@@ -45,8 +45,32 @@ test -f "${HOME}/.buildscripts/${PREFIX}.conf" && . "${HOME}/.buildscripts/${PRE
 : ${FORCE_BUILD:="no"}
 : ${DEB_BUILD_FOR:="debian:${DEBIAN_DISTROS} ubuntu:${UBUNTU_DISTROS}"}
 
+# These parts are not user-serviceable.
+TEMP_CLEANUP=""
+# End of non-user-serviceable part.
+
 set -ex
 
+# Cleans up temporary directories and files.
+# RFC SHOULD be called by trap handlers.
+cleanup () {
+	typeset -a temp_cleanup_arr
+	typeset OLDIFS="${IFS}"
+	IFS=":"
+	read -a temp_cleanup_arr <<< "${TEMP_CLEANUP}"
+	IFS="${OLDIFS}"
+
+	typeset temp_dir=""
+	for temp_dir in "${temp_cleanup_arr[@]}"; do
+		if [ -d "${temp_dir}" ]; then
+			rm -Rf "${temp_dir}"
+		fi
+	done
+}
+
+# Run cleanup() automatically.
+trap cleanup ERR EXIT SIGTERM SIGINT SIGHUP SIGPIPE SIGALRM SIGUSR1 SIGUSR2
+
 set_vars() {
 	USE_SUDO="yes"
 	PDEBUILD="pdebuild --pbuilder qemubuilder"
@@ -190,6 +214,7 @@ build_packages() {
 				test -z "${CODENAMES}" || grep "${CODENAMES}" <<< "${line}" || break
 
 				TEMP_DIR="$(mktemp -d --tmpdir=${TEMP_BASE})"
+				TEMP_CLEANUP="${TEMP_CLEANUP}:${TEMP_DIR}"
 				mkdir -p -- "${TEMP_DIR}/${PROJECT}"
 				chmod 2770 -Rf -- "${TEMP_DIR}"
 

--
Alioth's /srv/git/code.x2go.org/buildscripts.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/buildscripts.git


More information about the x2go-commits mailing list