]> code.ossystems Code Review - openembedded-core.git/commitdiff
sstate.bbclass: Remove possibility of file corruption and make package writing atomic
authorRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 22 Mar 2012 22:47:24 +0000 (22:47 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 23 Mar 2012 12:22:39 +0000 (12:22 +0000)
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>
meta/classes/sstate.bbclass

index 15706541aebb5eafc362ec0c85fba9adab020e69..20e66e274214fdedc884e65014f180419b749279 100644 (file)
@@ -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}