From c48e7308c19a7f804c2383b68e5afcd1517a7162 Mon Sep 17 00:00:00 2001 From: Martin Schwan Date: Wed, 17 Dec 2025 14:06:44 +0100 Subject: [PATCH] cargo-update-recipe-crates: Properly close target file after writing In do_update_crates(), properly close the target_file after writing to it using the "with" statement. Signed-off-by: Martin Schwan Signed-off-by: Mathieu Dubois-Briand Signed-off-by: Ross Burton Signed-off-by: Richard Purdie --- meta/classes-recipe/cargo-update-recipe-crates.bbclass | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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}'" -- 2.47.3