Truncate graphviz file before write

This commit is contained in:
Noah Santschi-Cooney 2020-08-07 00:59:04 +01:00
parent d773220c67
commit c67b329247
No known key found for this signature in database
GPG key ID: 3B22282472C8AE48

View file

@ -46,6 +46,7 @@ impl<'a> Invokeable for GraphDotCommand {
let filepath = rootpath + "/graph.dot";
eprintln!("generating dot file at {}", filepath);
let mut file = OpenOptions::new()
.truncate(true)
.write(true)
.create(true)
.open(filepath)
@ -53,6 +54,7 @@ impl<'a> Invokeable for GraphDotCommand {
let mut write_data_closure = || -> Result<(), std::io::Error> {
let graph = self.graph.as_ref();
file.seek(std::io::SeekFrom::Start(0))?;
file.write_all(dot::Dot::new(&(graph.borrow().graph)).to_string().as_bytes())?;
file.flush()?;