diff mbox series

[v2] sstatesig: write locked-sigs.inc atomically

Message ID 20261022150301.4033599-1-ricardo.salveti@oss.qualcomm.com
State Under Review
Headers show
Series [v2] sstatesig: write locked-sigs.inc atomically | expand

Commit Message

Ricardo Salveti Oct. 22, 2026, 3:03 p.m. UTC
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>
---
Changes in v2:
- Use os.replace() instead of os.rename() to make it clear that an
  existing locked-sigs.inc is replaced (same behaviour on Linux).

 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 9928f3af49..928fe2e44f 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):