diff mbox series

[v2,4/5] cargo-update-recipe-crates: Properly close target file after writing

Message ID 20251212091927.3741063-4-m.schwan@phytec.de
State New
Headers show
Series [v2,1/5] cargo-update-recipe-crates: Make do_update_crates() a Python function | expand

Commit Message

Martin Schwan Dec. 12, 2025, 9:19 a.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 v2:
  - Split changes into multiple patches, for improved readability
---
 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 6e82bd4a51..6e933d3afc 100644
--- a/meta/classes-recipe/cargo-update-recipe-crates.bbclass
+++ b/meta/classes-recipe/cargo-update-recipe-crates.bbclass
@@ -74,7 +74,8 @@  python do_update_crates() {
                     crates += c
     if crates is None:
         bb.error(f'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)
 
     bb.note(f'Successfully update crates inside \'{target_file}\'')
 }