Skip to content

Commit 03facd3

Browse files
committed
c2rust-transpile: only delete compile_commands.json if it was a temporary file we created
1 parent 3d85abc commit 03facd3

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

c2rust/src/bin/c2rust-transpile.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ fn main() {
226226
tcfg.emit_modules = true
227227
};
228228

229+
let mut created_temp_compile_commands = false;
230+
229231
let compile_commands = if args.compile_commands.len() == 1
230232
&& args.compile_commands[0].extension() == Some(std::ffi::OsStr::new("json"))
231233
{
@@ -244,6 +246,7 @@ fn main() {
244246
Exactly one compile_commands.json file should be provided, or a list of source files, but not both.");
245247
} else {
246248
// Handle as a list of source files
249+
created_temp_compile_commands = true;
247250
c2rust_transpile::create_temp_compile_commands(&args.compile_commands)
248251
};
249252

@@ -256,7 +259,7 @@ fn main() {
256259
c2rust_transpile::transpile(tcfg, &compile_commands, &extra_args);
257260

258261
// Remove the temporary compile_commands.json if it was created
259-
if args.compile_commands.len() > 0 {
262+
if created_temp_compile_commands {
260263
std::fs::remove_file(&compile_commands)
261264
.expect("Failed to remove temporary compile_commands.json");
262265
}

0 commit comments

Comments
 (0)