]> code.ossystems Code Review - openembedded-core.git/commitdiff
sstate: Reduce race windows
authorRichard Purdie <richard.purdie@linuxfoundation.org>
Sat, 3 Aug 2019 10:49:23 +0000 (11:49 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Sat, 3 Aug 2019 13:47:31 +0000 (14:47 +0100)
When we write to the sstate directory we try to do so atomically so
consumers either see one version or another but never an imcomplete file.
Unfortunately this is reliant on filesystem support and with some NFS
configurations a replaced file would be lost from memory even if users held
open descriptors.

It makes sense to try and avoid replacing existing files where we can.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes/sstate.bbclass

index ee029196dade8bb3116f0bcb387d35139ed52bcf..a0ca1998678ffabb24ddd057a267705a08b30490 100644 (file)
@@ -755,6 +755,11 @@ sstate_task_postfunc[dirs] = "${WORKDIR}"
 sstate_create_package () {
        TFILE=`mktemp ${SSTATE_PKG}.XXXXXXXX`
 
+       # Exit earlu if it already exists
+       if [ -e ${SSTATE_PKG} ]; then
+               return
+       fi
+
         # Use pigz if available
         OPT="-czS"
         if [ -x "$(command -v pigz)" ]; then
@@ -774,7 +779,12 @@ sstate_create_package () {
                tar $OPT --file=$TFILE --files-from=/dev/null
        fi
        chmod 0664 $TFILE
-       mv -f $TFILE ${SSTATE_PKG}
+       # Skip if it was already created by some other process
+       if [ ! -e ${SSTATE_PKG} ]; then
+               mv -f $TFILE ${SSTATE_PKG}
+       else
+               rm $TFILE
+       fi
 }
 
 python sstate_sign_package () {