Patchwork sstate.bbclass: Remove possibility of file corruption and make package writing atomic

login
register
mail settings
Submitter Richard Purdie
Date March 22, 2012, 10:47 p.m.
Message ID <1332456444.9740.351.camel@ted>
Download mbox | patch
Permalink /patch/24201/
State Accepted
Commit 52bf113e786a57123a9da98f64442afbc2f1471e
Headers show

Comments

Richard Purdie - March 22, 2012, 10:47 p.m.
There is currently a race window when creating sstate packages since we don't
atomically write the files to SSTATE_DIR. This change ensures we do so by writing
to a temporary file and then doing an atomic move.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---

Patch

diff --git a/meta/classes/sstate.bbclass b/meta/classes/sstate.bbclass
index 1570654..20e66e2 100644
--- a/meta/classes/sstate.bbclass
+++ b/meta/classes/sstate.bbclass
@@ -455,12 +455,14 @@  python sstate_task_postfunc () {
 #
 sstate_create_package () {
 	cd ${SSTATE_BUILDDIR}
+	TFILE=`mktemp ${SSTATE_PKG}.XXXXXXXX`
 	# Need to handle empty directories
 	if [ "$(ls -A)" ]; then
-		tar -czf ${SSTATE_PKG} *
+		tar -czf $TFILE *
 	else
-		tar -cz --file=${SSTATE_PKG} --files-from=/dev/null
+		tar -cz --file=$TFILE --files-from=/dev/null
 	fi
+	mv $TFILE ${SSTATE_PKG}
 
 	cd ${WORKDIR}
 	rm -rf ${SSTATE_BUILDDIR}