Skip to content

Commit

Permalink
Changed concat logic in file storage. (#63)
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Kirilin <[email protected]>
  • Loading branch information
s3rius authored Mar 26, 2022
1 parent 33ba484 commit cc0a468
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/storages/file_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ impl Storage for FileStorage {
parts_info: Vec<FileInfo>,
) -> 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)
Expand All @@ -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);
Expand All @@ -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?
Expand Down

0 comments on commit cc0a468

Please sign in to comment.