From cc0a4684a1fadb987b38b49eb552793c3f7209b9 Mon Sep 17 00:00:00 2001 From: Pavel Kirilin Date: Sat, 26 Mar 2022 14:13:50 +0400 Subject: [PATCH] Changed concat logic in file storage. (#63) Signed-off-by: Pavel Kirilin --- src/storages/file_storage.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/storages/file_storage.rs b/src/storages/file_storage.rs index 86bf09d..29c431b 100644 --- a/src/storages/file_storage.rs +++ b/src/storages/file_storage.rs @@ -144,8 +144,9 @@ impl Storage for FileStorage { parts_info: Vec, ) -> RustusResult<()> { let info = file_info.clone(); + let force_fsync = self.force_fsync; tokio::task::spawn_blocking(move || { - let mut file = OpenOptions::new() + let file = OpenOptions::new() .write(true) .append(true) .create(true) @@ -154,6 +155,7 @@ impl Storage for FileStorage { error!("{:?}", err); RustusError::UnableToWrite(err.to_string()) })?; + let mut writer = BufWriter::new(file); for part in parts_info { if part.path.is_none() { return Err(RustusError::FileNotFound); @@ -162,9 +164,12 @@ impl Storage for FileStorage { .read(true) .open(part.path.as_ref().unwrap())?; let mut reader = BufReader::new(part_file); - copy(&mut reader, &mut file)?; + copy(&mut reader, &mut writer)?; + } + writer.flush()?; + if force_fsync { + writer.get_ref().sync_data()?; } - file.sync_data()?; Ok(()) }) .await?