Skip to content

Commit ba43ff0

Browse files
committed
libvirt: Remove predictable named file in /tmp
This one shouldn't have gotten through code review, I noticed it when debugging something else. Signed-off-by: Colin Walters <walters@verbum.org>
1 parent 33596cd commit ba43ff0

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

crates/kit/src/libvirt/run.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use clap::{Parser, ValueEnum};
99
use color_eyre::eyre;
1010
use color_eyre::{eyre::Context, Result};
1111
use std::fs;
12+
use std::io::Write;
1213
use std::str::FromStr;
1314
use tracing::{debug, info};
1415

@@ -1296,8 +1297,13 @@ fn create_libvirt_domain_from_disk(
12961297
.with_context(|| "Failed to build domain XML")?;
12971298

12981299
// Write XML to temporary file
1299-
let xml_path = format!("/tmp/{}.xml", domain_name);
1300-
std::fs::write(&xml_path, domain_xml).with_context(|| "Failed to write domain XML")?;
1300+
let mut tmp_domain_file = tempfile::NamedTempFile::with_prefix("bcvk-libvirt")?;
1301+
tmp_domain_file
1302+
.as_file_mut()
1303+
.write_all(domain_xml.as_bytes())
1304+
.with_context(|| "Failed to write domain XML")?;
1305+
let xml_path: &Utf8Path = tmp_domain_file.path().try_into()?;
1306+
let xml_path = xml_path.as_str();
13011307

13021308
let connect_uri = global_opts.connect.as_deref();
13031309

@@ -1323,8 +1329,5 @@ fn create_libvirt_domain_from_disk(
13231329
)?;
13241330
}
13251331

1326-
// Clean up temporary XML file
1327-
let _ = std::fs::remove_file(&xml_path);
1328-
13291332
Ok(())
13301333
}

0 commit comments

Comments
 (0)