From 03facd34b3722ba981696df9057057f1cf100d91 Mon Sep 17 00:00:00 2001 From: fw Date: Wed, 10 Apr 2024 11:02:29 -0400 Subject: [PATCH] c2rust-transpile: only delete compile_commands.json if it was a temporary file we created --- c2rust/src/bin/c2rust-transpile.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/c2rust/src/bin/c2rust-transpile.rs b/c2rust/src/bin/c2rust-transpile.rs index ecc1dfe970..165b1edcda 100644 --- a/c2rust/src/bin/c2rust-transpile.rs +++ b/c2rust/src/bin/c2rust-transpile.rs @@ -226,6 +226,8 @@ fn main() { tcfg.emit_modules = true }; + let mut created_temp_compile_commands = false; + let compile_commands = if args.compile_commands.len() == 1 && args.compile_commands[0].extension() == Some(std::ffi::OsStr::new("json")) { @@ -244,6 +246,7 @@ fn main() { Exactly one compile_commands.json file should be provided, or a list of source files, but not both."); } else { // Handle as a list of source files + created_temp_compile_commands = true; c2rust_transpile::create_temp_compile_commands(&args.compile_commands) }; @@ -256,7 +259,7 @@ fn main() { c2rust_transpile::transpile(tcfg, &compile_commands, &extra_args); // Remove the temporary compile_commands.json if it was created - if args.compile_commands.len() > 0 { + if created_temp_compile_commands { std::fs::remove_file(&compile_commands) .expect("Failed to remove temporary compile_commands.json"); }