We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a7af065 commit 9a7facfCopy full SHA for 9a7facf
1 file changed
src/structures/state.rs
@@ -1,7 +1,8 @@
1
use serde_json::{from_reader, to_writer_pretty};
2
use serde::{Deserialize, Serialize};
3
-use std::{path::Path, fs::{File, OpenOptions}};
4
-use super::{Snippet};
+use std::fs::{self, File, OpenOptions };
+use std::path::Path;
5
+use super::Snippet;
6
7
#[derive(Deserialize, Serialize)]
8
pub struct State {
@@ -30,6 +31,11 @@ impl State {
30
31
32
pub fn write(&self, file_path: &str) {
33
let path = Path::new(file_path);
34
+
35
+ if path.exists() {
36
+ fs::remove_file(path).expect("Failed to delete old file.");
37
+ }
38
39
let result = OpenOptions::new()
40
.read(true)
41
.write(true)
0 commit comments