From 71e0a1b7de1c4063a5f35cc47d56b9991f7b03da Mon Sep 17 00:00:00 2001 From: Congyu <52687642+Congyuwang@users.noreply.github.com> Date: Fri, 29 Mar 2024 19:21:12 +0800 Subject: [PATCH] fix RocksDictConfig save not truncating (#117) --- src/rdict.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/rdict.rs b/src/rdict.rs index 8cfb7bb..6f0f30e 100644 --- a/src/rdict.rs +++ b/src/rdict.rs @@ -120,7 +120,11 @@ impl RocksDictConfig { } pub fn save>(&self, path: P) -> PyResult<()> { - let config_file = fs::File::options().create(true).write(true).open(path)?; + let config_file = fs::File::options() + .create(true) + .truncate(true) + .write(true) + .open(path)?; match serde_json::to_writer(config_file, self) { Ok(_) => Ok(()), Err(e) => Err(PyException::new_err(e.to_string())),