[X2Go-Commits] [buildscripts] 01/06: bin/build-rpm-package: add cleanup() function and signal handlers.

git-admin at x2go.org git-admin at x2go.org
Wed Apr 1 07:34:40 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 452048972380f27a28e47d44094140580895dd73
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Wed Apr 1 06:39:43 2015 +0200

    bin/build-rpm-package: add cleanup() function and signal handlers.
---
 bin/build-rpm-package |   51 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/bin/build-rpm-package b/bin/build-rpm-package
index 67c451f..7be653e 100755
--- a/bin/build-rpm-package
+++ b/bin/build-rpm-package
@@ -56,8 +56,59 @@ NO_DELAY=${NO_DELAY:-"no"}
 FORCE_BUILD=${FORCE_BUILD:-"no"}
 RPM_BUILD_FOR=${RPM_BUILD_FOR:-"fedora:$FEDORA_DISTROS epel:$EPEL_DISTROSi opensuse:$OPENSUSE_DISTROS" sle:$SLE_DISTROS}
 
+# These parts are not user-servicable.
+TMP_MOCK_CFG_DIR=""
+TMP_MOCK_CFG_FILE=""
+# End of non-user-servicable part.
+
 set -ex
 
+# Cleans up temporary directories and files.
+# RFC SHOULD be called by trap handlers.
+cleanup () {
+	# We always assume the temporary mock config file is below the temporary config directory.
+	if [ -n "${TMP_MOCK_CFG_DIR}" ]; then
+		# Take care of the config file first.
+		if [ -n "${TMP_MOCK_CFG_FILE}" ]; then
+			if [ -e "${TMP_MOCK_CFG_FILE}" ]; then
+				# Explicit test after the general existence test so that we can
+				# print an error message if the file we're looking at is not a
+				# regular file.
+				# BEWARE OF RACE CONDITIONS, though.
+				if [ -f "${TMP_MOCK_CFG_FILE}" ]; then
+					rm "${TMP_MOCK_CFG_DIR}/${TMP_MOCK_CFG_FILE}"
+				else
+					echo "Warning: file '$(readlink -nf "${TMP_MOCK_CFG_DIR}/${TMP_MOCK_CFG_FILE}")' is not a regular file. Not unlinking." >&2
+				fi
+			else
+				echo "Warning: mock temporary config directory set as ${TMP_MOCK_CFG_DIR}, but mock temporary config file ${TMP_MOCK_CFG_FILE} does not exist." >&2
+			fi
+		else
+			echo "Warning: mock temporary config directory set as ${TMP_MOCK_CFG_DIR}, but mock temporary config file unknown." >&2
+		fi
+
+		# And only later of the directory itself.
+		if [ -e "${TMP_MOCK_CFG_DIR}" ]; then
+			if [ -d "${TMP_MOCK_CFG_DIR}" ]; then
+				rmdir "${TMP_MOCK_CFG_DIR}" || echo "Warning: unable to remove mock temporary config directory ${TMP_MOCK_CFG_DIR}. Is it non-empty?" >&2
+			else
+				echo "Warning: mock temporary config directory ${TMP_MOCK_CFG_DIR} is not actually a directory. Not unlinking." >&2
+			fi
+		else
+			echo "Warning: mock temporary config directory ${TMP_MOCK_CFG_DIR} does not exist." >&2
+		fi
+	else
+		if [ -n "${TMP_MOCK_CFG_FILE}" ]; then
+			echo "Warning: mock temp not set, but temporary mock config file ${TMP_MOCK_CFG_FILE} set." >&2
+		else
+			echo "Warning: did not find any mock temporary config directory or file set. Not removing anything." >&2
+		fi
+	fi
+}
+
+# Run cleanup() automatically.
+trap cleanup EXIT SIGTERM SIGINT SIGHUP SIGPIPE SIGALRM SIGUSR1 SIGUSR2
+
 set_vars() {
 	TEMP_BASE="$HOME/tmp/"
 	mkdir -p "$TEMP_BASE"

--
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