diff mbox series

[v3,2/2] cargo-update-recipe-crates: Properly close target file after writing

Message ID 20251217130644.2710575-2-m.schwan@phytec.de
State New
Headers show
Series [v3,1/2] cargo-update-recipe-crates: Don't fail for partially empty Cargo.lock | expand

Commit Message

Martin Schwan Dec. 17, 2025, 1:06 p.m. UTC
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>
---
Changes in v3:
  - Revert back to piping Python code to native Python
---
 meta/classes-recipe/cargo-update-recipe-crates.bbclass | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/meta/classes-recipe/cargo-update-recipe-crates.bbclass b/meta/classes-recipe/cargo-update-recipe-crates.bbclass
index ffc658f0f1..47e845c822 100644
--- a/meta/classes-recipe/cargo-update-recipe-crates.bbclass
+++ b/meta/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}'"