diff mbox series

[blacksail,53/60] sstatesig: write locked-sigs.inc atomically

Message ID b30dc96d6b282807d845ae4904e6a78b89c7e0f4.1793867929.git.yoann.congal@smile.fr
State RFC, archived
Delegated to: Yoann Congal
Headers show
Series [blacksail,01/60] gstreamer1.0-plugins-bad: use gtk+3 dependency name | expand

Commit Message

Yoann Congal Nov. 5, 2026, 8:43 a.m. UTC
From: Ricardo Salveti <ricardo.salveti@oss.qualcomm.com>

dump_lockedsigs() writes the sigfile in place, so if bitbake fails or is
killed partway through, for example on a full disk, a truncated
locked-sigs.inc is left behind. yocto-check-layer's test_signatures and
test_machine_signatures run bitbake with -k and ignore its exit status
when the file exists, so they would compare a partial set of signatures
without noticing.

Write to locked-sigs.inc.new and move it over locked-sigs.inc with
os.replace() once complete, as epochfile_write() in oe/reproducible.py
does, so a failed dump leaves no sigfile behind.

Tested by making dump_lockedsigs() fail with ENOSPC halfway through on
meta-qcom data: yocto-check-layer previously accepted the partial file,
now it reports the error. Complete output is byte-identical and a
meta-qcom yocto-check-layer run gives the same results as before.

AI-Generated: Uses Claude Code (Claude Opus 5.5)
Signed-off-by: Ricardo Salveti <ricardo.salveti@oss.qualcomm.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(cherry picked from commit 54a5173ff507de4b2bfd54bd12a6836fb6129286)
Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
---
 meta/lib/oe/sstatesig.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/meta/lib/oe/sstatesig.py b/meta/lib/oe/sstatesig.py
index 9928f3af495..928fe2e44f8 100644
--- a/meta/lib/oe/sstatesig.py
+++ b/meta/lib/oe/sstatesig.py
@@ -259,7 +259,8 @@  class SignatureGeneratorOEBasicHashMixIn(object):
             if taskhash != unihash:
                 unihashmap[tid] = "    " + self.lockedpnmap[fn] + ":" + task + ":" + taskhash + ":" + unihash
 
-        with open(sigfile, "w") as f:
+        tmpfile = sigfile + ".new"
+        with open(tmpfile, "w") as f:
             l = sorted(types)
             for t in l:
                 f.write('SIGGEN_LOCKEDSIGS_%s = "\\\n' % t)
@@ -277,6 +278,7 @@  class SignatureGeneratorOEBasicHashMixIn(object):
             for tid in sortedtid:
                 f.write(unihashmap[tid] + " \\\n")
             f.write('    "\n')
+        os.replace(tmpfile, sigfile)
 
     def dump_siglist(self, sigfile, path_prefix_strip=None):
         def strip_fn(fn):