Skip to content

Commit

Permalink
try File::write()
Browse files Browse the repository at this point in the history
Signed-off-by: Tarek <[email protected]>
  • Loading branch information
tareknaser committed Jun 12, 2024
1 parent 1b55b6e commit 3027100
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions fs-storage/src/file_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,17 @@ where
})?;
fs::create_dir_all(parent_dir)?;
let mut file = File::create(&self.path)?;
file.write_all(serde_json::to_string_pretty(&self.data)?.as_bytes())?;
// file.write_all(serde_json::to_string_pretty(&self.data)?.as_bytes())?;
// file.flush()?;
// // Sync the file to disk to ensure metadata is updated
// file.sync_all()?;

// use File::write
let data = serde_json::to_string_pretty(&self.data)?;
File::write(&mut file, data.as_bytes())?;
file.flush()?;
// Sync the file to disk to ensure metadata is updated
file.sync_all()?;
drop(file);

let new_timestamp = fs::metadata(&self.path)?.modified()?;
if new_timestamp == self.modified {
Expand Down

0 comments on commit 3027100

Please sign in to comment.