Skip to content

Commit

Permalink
Merge branch 'release/0.4.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
s3rius committed Feb 24, 2022
2 parents 584ad15 + 6029124 commit 985c064
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rustus"
version = "0.4.3"
version = "0.4.4"
edition = "2021"
description = "TUS protocol implementation written in Rust."

Expand Down Expand Up @@ -113,5 +113,5 @@ httptest = "0.15.4"
[profile.release]
lto = true
panic = "abort"
opt-level = "z"
opt-level = 2
codegen-units = 1
30 changes: 7 additions & 23 deletions src/info_storages/file_info_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::PathBuf;
use async_trait::async_trait;
use log::error;
use tokio::fs::{read_to_string, remove_file, DirBuilder, OpenOptions};
use tokio::io::{AsyncWriteExt, BufWriter};
use tokio::io::copy;

use crate::errors::{RustusError, RustusResult};
use crate::info_storages::{FileInfo, InfoStorage};
Expand Down Expand Up @@ -35,7 +35,7 @@ impl InfoStorage for FileInfoStorage {
}

async fn set_info(&self, file_info: &FileInfo, create: bool) -> RustusResult<()> {
let file = OpenOptions::new()
let mut file = OpenOptions::new()
.write(true)
.create(create)
.truncate(true)
Expand All @@ -45,27 +45,11 @@ impl InfoStorage for FileInfoStorage {
error!("{:?}", err);
RustusError::UnableToWrite(err.to_string())
})?;
let mut writer = BufWriter::new(file);
writer
.write(
serde_json::to_string(&file_info)
.map_err(|err| {
error!("{:#?}", err);
err
})?
.as_bytes(),
)
.await
.map_err(|err| {
error!("{:?}", err);
RustusError::UnableToWrite(
self.info_file_path(file_info.id.as_str())
.as_path()
.display()
.to_string(),
)
})?;
writer.flush().await?;
let data = serde_json::to_string(&file_info).map_err(|err| {
error!("{:#?}", err);
err
})?;
copy(&mut data.as_bytes(), &mut file).await?;
Ok(())
}

Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg_attr(coverage, feature(no_coverage))]

use std::str::FromStr;
use std::sync::Arc;

Expand Down
15 changes: 4 additions & 11 deletions src/storages/file_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use actix_files::NamedFile;
use async_trait::async_trait;
use log::error;
use tokio::fs::{remove_file, DirBuilder, OpenOptions};
use tokio::io::{copy, AsyncWriteExt, BufWriter};
use tokio::io::{copy, BufReader};

use crate::errors::{RustusError, RustusResult};
use crate::info_storages::FileInfo;
Expand Down Expand Up @@ -85,7 +85,7 @@ impl Storage for FileStorage {
// Opening file in w+a mode.
// It means that we're going to append some
// bytes to the end of a file.
let file = OpenOptions::new()
let mut file = OpenOptions::new()
.write(true)
.append(true)
.create(false)
Expand All @@ -95,15 +95,8 @@ impl Storage for FileStorage {
error!("{:?}", err);
RustusError::UnableToWrite(err.to_string())
})?;
let mut writer = BufWriter::new(file);
writer.write(bytes).await.map_err(|err| {
error!("{:?}", err);
RustusError::UnableToWrite(info.path.clone().unwrap())
})?;
writer.flush().await.map_err(|err| {
error!("{:?}", err);
RustusError::UnableToWrite(info.path.clone().unwrap())
})?;
let mut reader = BufReader::new(bytes);
copy(&mut reader, &mut file).await?;
Ok(())
}

Expand Down

0 comments on commit 985c064

Please sign in to comment.