From b0ce0e4749c3c2000eaca09b6c8f6b26d6f40d02 Mon Sep 17 00:00:00 2001 From: Peter Neuroth Date: Fri, 18 Oct 2024 16:07:26 +0200 Subject: [PATCH] cli: Add I/O sync to filesystem 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 --- libs/gl-cli/src/util.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/gl-cli/src/util.rs b/libs/gl-cli/src/util.rs index 1362ffb64..6d11c24b8 100644 --- a/libs/gl-cli/src/util.rs +++ b/libs/gl-cli/src/util.rs @@ -34,6 +34,7 @@ pub fn write_seed(file_path: impl AsRef, seed: impl AsRef<[u8]>) -> Result let mut file = File::create(file_path)?; file.write_all(seed.as_ref())?; + file.sync_all()?; Ok(()) } @@ -43,6 +44,7 @@ pub fn write_seed(file_path: impl AsRef, seed: impl AsRef<[u8]>) -> Result pub fn write_credentials(file_path: impl AsRef, creds: impl AsRef<[u8]>) -> Result<()> { let mut file = File::create(&file_path)?; file.write_all(creds.as_ref())?; + file.sync_all()?; Ok(()) }