diff mbox series

[meta-lts-mixins,scarthgap/rust,03/35] cargo-update-recipe-crates: Properly close target file after writing

Message ID f0cba7dcc24d81f9c1b3752dfd8fa5d92488c75a.1785496469.git.scott.murray@konsulko.com
State New
Headers show
Series Update to 1.96.1 | expand

Commit Message

Scott Murray July 31, 2026, 11:32 a.m. UTC
From: Martin Schwan <m.schwan@phytec.de>

In do_update_crates(), properly close the target_file after writing to
it using the "with" statement.

Signed-off-by: Martin Schwan <m.schwan@phytec.de>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(adapted from oe-core commit c48e7308c19a7f804c2383b68e5afcd1517a7162)
Signed-off-by: Scott Murray <scott.murray@konsulko.com>
---
 classes-recipe/cargo-update-recipe-crates.bbclass | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/classes-recipe/cargo-update-recipe-crates.bbclass b/classes-recipe/cargo-update-recipe-crates.bbclass
index ffc658f..47e845c 100644
--- a/classes-recipe/cargo-update-recipe-crates.bbclass
+++ b/classes-recipe/cargo-update-recipe-crates.bbclass
@@ -72,7 +72,8 @@  for root, dirs, files in os.walk('${CARGO_LOCK_SRC_DIR}'):
                 crates += c
 if crates is None:
     raise ValueError("Unable to find any Cargo.lock in ${CARGO_LOCK_SRC_DIR}")
-open("${TARGET_FILE}", 'w').write(crates)
+with open("${TARGET_FILE}", 'w') as f:
+    f.write(crates)
 EOF
 
     bbnote "Successfully update crates inside '${TARGET_FILE}'"