Skip to content

Commit

Permalink
cli: Add I/O sync to filesystem
Browse files Browse the repository at this point in the history
A flush is not needed here as `File` utilizes Os memory (afaict) which
will write to the fs once we drop the `File`.

We still a manual `sync_all()` to catch any errors that could arise
writing to the fs that we would miss if we just drop the `File`.

Signed-off-by: Peter Neuroth <[email protected]>
  • Loading branch information
nepet committed Oct 18, 2024
1 parent c828b1e commit b0ce0e4
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libs/gl-cli/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub fn write_seed(file_path: impl AsRef<Path>, seed: impl AsRef<[u8]>) -> Result

let mut file = File::create(file_path)?;
file.write_all(seed.as_ref())?;
file.sync_all()?;

Ok(())
}
Expand All @@ -43,6 +44,7 @@ pub fn write_seed(file_path: impl AsRef<Path>, seed: impl AsRef<[u8]>) -> Result
pub fn write_credentials(file_path: impl AsRef<Path>, creds: impl AsRef<[u8]>) -> Result<()> {
let mut file = File::create(&file_path)?;
file.write_all(creds.as_ref())?;
file.sync_all()?;

Ok(())
}
Expand Down

0 comments on commit b0ce0e4

Please sign in to comment.