Skip to content

Commit 8b855f0

Browse files
committed
sync fs
1 parent 836bcf2 commit 8b855f0

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/config.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ impl State {
161161
}
162162

163163
pub async fn async_save(&self, path: impl AsRef<Path>) -> Result<(), Error> {
164-
let path_tmp = path.as_ref().with_extension("tmp");
164+
let path = path.as_ref();
165+
let path_tmp = path.with_extension("tmp");
165166
let mut fpb = tokio::fs::OpenOptions::new();
166167
let fpb = fpb.create(true).write(true).truncate(true);
167168
let mut fp = fpb.open(&path_tmp).await?;
@@ -170,6 +171,8 @@ impl State {
170171
fp.sync_data().await?;
171172
mem::drop(fp);
172173
tokio::fs::rename(path_tmp, path).await?;
174+
let dir = tokio::fs::File::open(path.parent().unwrap_or_else(|| Path::new("."))).await?;
175+
dir.sync_all().await?;
173176
Ok(())
174177
}
175178

0 commit comments

Comments
 (0)