-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
Signed-off-by: Pavel Kirilin <[email protected]>
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ pub trait Storage { | |
/// It MUST throw errors if connection can't | ||
/// be established or in any other case that might | ||
/// be a problem later on. | ||
async fn prepare(&mut self) -> anyhow::Result<()>; | ||
async fn prepare(&mut self) -> RustusResult<()>; | ||
Check failure on line 21 in src/data_storage/base.rs GitHub Actions / clippyfunctions in traits cannot be declared `async`
|
||
|
||
/// Get contents of a file. | ||
/// | ||
|
@@ -48,7 +48,7 @@ pub trait Storage { | |
/// # Params | ||
/// `file_info` - info about current file. | ||
/// `bytes` - bytes to append to the file. | ||
async fn add_bytes(&self, file_info: &FileInfo, bytes: Bytes) -> anyhow::Result<()>; | ||
async fn add_bytes(&self, file_info: &FileInfo, bytes: Bytes) -> RustusResult<()>; | ||
Check failure on line 51 in src/data_storage/base.rs GitHub Actions / clippyfunctions in traits cannot be declared `async`
|
||
|
||
/// Create file in storage. | ||
/// | ||
|
@@ -58,7 +58,7 @@ pub trait Storage { | |
/// | ||
/// # Params | ||
/// `file_info` - info about current file. | ||
async fn create_file(&self, file_info: &FileInfo) -> anyhow::Result<String>; | ||
async fn create_file(&self, file_info: &FileInfo) -> RustusResult<String>; | ||
Check failure on line 61 in src/data_storage/base.rs GitHub Actions / clippyfunctions in traits cannot be declared `async`
|
||
|
||
/// Concatenate files. | ||
/// | ||
|
@@ -73,7 +73,7 @@ pub trait Storage { | |
&self, | ||
file_info: &FileInfo, | ||
parts_info: Vec<FileInfo>, | ||
) -> anyhow::Result<()>; | ||
) -> RustusResult<()>; | ||
Check failure on line 76 in src/data_storage/base.rs GitHub Actions / clippyfunctions in traits cannot be declared `async`
|
||
|
||
/// Remove file from storage | ||
/// | ||
|
@@ -82,5 +82,5 @@ pub trait Storage { | |
/// | ||
/// # Params | ||
/// `file_info` - info about current file. | ||
async fn remove_file(&self, file_info: &FileInfo) -> anyhow::Result<()>; | ||
async fn remove_file(&self, file_info: &FileInfo) -> RustusResult<()>; | ||
Check failure on line 85 in src/data_storage/base.rs GitHub Actions / clippyfunctions in traits cannot be declared `async`
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ impl FileStorage { | |
} | ||
} | ||
|
||
pub fn data_file_path(&self, file_id: &str) -> anyhow::Result<PathBuf> { | ||
pub fn data_file_path(&self, file_id: &str) -> RustusResult<PathBuf> { | ||
let dir = self | ||
.data_dir | ||
// We're working wit absolute paths, because tus.io says so. | ||
|
@@ -48,7 +48,7 @@ impl Storage for FileStorage { | |
"file" | ||
} | ||
|
||
async fn prepare(&mut self) -> anyhow::Result<()> { | ||
async fn prepare(&mut self) -> RustusResult<()> { | ||
Check failure on line 51 in src/data_storage/file_storage.rs GitHub Actions / clippyfunctions in traits cannot be declared `async`
|
||
// We're creating directory for new files | ||
// if it doesn't already exist. | ||
if !self.data_dir.exists() { | ||
|
@@ -78,7 +78,7 @@ impl Storage for FileStorage { | |
Ok((headers, body).into_response()) | ||
} | ||
|
||
async fn add_bytes(&self, file_info: &FileInfo, bytes: Bytes) -> anyhow::Result<()> { | ||
async fn add_bytes(&self, file_info: &FileInfo, bytes: Bytes) -> RustusResult<()> { | ||
Check failure on line 81 in src/data_storage/file_storage.rs GitHub Actions / clippyfunctions in traits cannot be declared `async`
|
||
// In normal situation this `if` statement is not | ||
// gonna be called, but what if it is ... | ||
if file_info.path.is_none() { | ||
|
@@ -108,7 +108,7 @@ impl Storage for FileStorage { | |
.await? | ||
} | ||
|
||
async fn create_file(&self, file_info: &FileInfo) -> anyhow::Result<String> { | ||
async fn create_file(&self, file_info: &FileInfo) -> RustusResult<String> { | ||
Check failure on line 111 in src/data_storage/file_storage.rs GitHub Actions / clippyfunctions in traits cannot be declared `async`
|
||
// New path to file. | ||
let file_path = self.data_file_path(file_info.id.as_str())?; | ||
tokio::task::spawn_blocking(move || { | ||
|
@@ -128,7 +128,7 @@ impl Storage for FileStorage { | |
&self, | ||
file_info: &FileInfo, | ||
parts_info: Vec<FileInfo>, | ||
) -> anyhow::Result<()> { | ||
) -> RustusResult<()> { | ||
Check failure on line 131 in src/data_storage/file_storage.rs GitHub Actions / clippyfunctions in traits cannot be declared `async`
|
||
let force_fsync = self.force_fsync; | ||
let path = file_info.path.as_ref().unwrap().clone(); | ||
tokio::task::spawn_blocking(move || { | ||
|
@@ -157,7 +157,7 @@ impl Storage for FileStorage { | |
.await? | ||
} | ||
|
||
async fn remove_file(&self, file_info: &FileInfo) -> anyhow::Result<()> { | ||
async fn remove_file(&self, file_info: &FileInfo) -> RustusResult<()> { | ||
Check failure on line 160 in src/data_storage/file_storage.rs GitHub Actions / clippyfunctions in traits cannot be declared `async`
|
||
let info = file_info.clone(); | ||
tokio::task::spawn_blocking(move || { | ||
// Let's remove the file itself. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use crate::config::Config; | ||
use crate::{config::Config, errors::RustusResult}; | ||
|
||
pub mod base; | ||
pub mod file_storage; | ||
|
@@ -11,7 +11,7 @@ pub enum DataStorageImpl { | |
} | ||
|
||
impl DataStorageImpl { | ||
pub fn new(_config: &Config) -> anyhow::Result<Self> { | ||
pub fn new(_config: &Config) -> RustusResult<Self> { | ||
Ok(Self::File(file_storage::FileStorage::new( | ||
"./data".into(), | ||
"{year}/{month}/{day}/".into(), | ||
|
@@ -28,7 +28,7 @@ impl base::Storage for DataStorageImpl { | |
} | ||
} | ||
|
||
async fn prepare(&mut self) -> anyhow::Result<()> { | ||
async fn prepare(&mut self) -> RustusResult<()> { | ||
Check failure on line 31 in src/data_storage/mod.rs GitHub Actions / clippyfunctions in traits cannot be declared `async`
|
||
match self { | ||
Self::File(file) => file.prepare().await, | ||
Self::S3Hybrid(s3) => s3.prepare().await, | ||
|
@@ -50,7 +50,7 @@ impl base::Storage for DataStorageImpl { | |
&self, | ||
file_info: &crate::models::file_info::FileInfo, | ||
bytes: bytes::Bytes, | ||
) -> anyhow::Result<()> { | ||
) -> RustusResult<()> { | ||
Check failure on line 53 in src/data_storage/mod.rs GitHub Actions / clippyfunctions in traits cannot be declared `async`
|
||
match self { | ||
Self::File(file) => file.add_bytes(file_info, bytes).await, | ||
Self::S3Hybrid(s3) => s3.add_bytes(file_info, bytes).await, | ||
|
@@ -60,7 +60,7 @@ impl base::Storage for DataStorageImpl { | |
async fn create_file( | ||
&self, | ||
file_info: &crate::models::file_info::FileInfo, | ||
) -> anyhow::Result<String> { | ||
) -> RustusResult<String> { | ||
Check failure on line 63 in src/data_storage/mod.rs GitHub Actions / clippyfunctions in traits cannot be declared `async`
|
||
match self { | ||
Self::File(file) => file.create_file(file_info).await, | ||
Self::S3Hybrid(s3) => s3.create_file(file_info).await, | ||
|
@@ -71,7 +71,7 @@ impl base::Storage for DataStorageImpl { | |
&self, | ||
file_info: &crate::models::file_info::FileInfo, | ||
parts_info: Vec<crate::models::file_info::FileInfo>, | ||
) -> anyhow::Result<()> { | ||
) -> RustusResult<()> { | ||
Check failure on line 74 in src/data_storage/mod.rs GitHub Actions / clippyfunctions in traits cannot be declared `async`
|
||
match self { | ||
Self::File(file) => file.concat_files(file_info, parts_info).await, | ||
Self::S3Hybrid(s3) => s3.concat_files(file_info, parts_info).await, | ||
|
@@ -81,7 +81,7 @@ impl base::Storage for DataStorageImpl { | |
async fn remove_file( | ||
&self, | ||
file_info: &crate::models::file_info::FileInfo, | ||
) -> anyhow::Result<()> { | ||
) -> RustusResult<()> { | ||
Check failure on line 84 in src/data_storage/mod.rs GitHub Actions / clippyfunctions in traits cannot be declared `async`
|
||
match self { | ||
Self::File(file) => file.remove_file(file_info).await, | ||
Self::S3Hybrid(s3) => s3.remove_file(file_info).await, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,7 +99,7 @@ impl S3HybridStorage { | |
/// | ||
/// This function is called to upload file to s3 completely. | ||
/// It streams file directly from disk to s3. | ||
async fn upload_file(&self, file_info: &FileInfo) -> anyhow::Result<()> { | ||
async fn upload_file(&self, file_info: &FileInfo) -> RustusResult<()> { | ||
if file_info.path.is_none() { | ||
return Err(RustusError::UnableToWrite("Cannot get upload path.".into()).into()); | ||
} | ||
|
@@ -128,7 +128,7 @@ impl Storage for S3HybridStorage { | |
"s3_hybrid" | ||
} | ||
|
||
async fn prepare(&mut self) -> anyhow::Result<()> { | ||
async fn prepare(&mut self) -> RustusResult<()> { | ||
Check failure on line 131 in src/data_storage/s3_hybrid.rs GitHub Actions / clippyfunctions in traits cannot be declared `async`
|
||
Ok(()) | ||
} | ||
|
||
|
@@ -150,7 +150,7 @@ impl Storage for S3HybridStorage { | |
Ok(([disp.0, disp.1], body).into_response()) | ||
} | ||
|
||
async fn add_bytes(&self, file_info: &FileInfo, bytes: Bytes) -> anyhow::Result<()> { | ||
async fn add_bytes(&self, file_info: &FileInfo, bytes: Bytes) -> RustusResult<()> { | ||
Check failure on line 153 in src/data_storage/s3_hybrid.rs GitHub Actions / clippyfunctions in traits cannot be declared `async`
|
||
let part_len = bytes.len(); | ||
self.local_storage.add_bytes(file_info, bytes).await?; | ||
// If upload is complete. Upload the resulting file onto S3. | ||
|
@@ -161,19 +161,19 @@ impl Storage for S3HybridStorage { | |
Ok(()) | ||
} | ||
|
||
async fn create_file(&self, file_info: &FileInfo) -> anyhow::Result<String> { | ||
async fn create_file(&self, file_info: &FileInfo) -> RustusResult<String> { | ||
Check failure on line 164 in src/data_storage/s3_hybrid.rs GitHub Actions / clippyfunctions in traits cannot be declared `async`
|
||
self.local_storage.create_file(file_info).await | ||
} | ||
|
||
async fn concat_files( | ||
&self, | ||
_file_info: &FileInfo, | ||
_parts_info: Vec<FileInfo>, | ||
) -> anyhow::Result<()> { | ||
) -> RustusResult<()> { | ||
Check failure on line 172 in src/data_storage/s3_hybrid.rs GitHub Actions / clippyfunctions in traits cannot be declared `async`
|
||
Err(RustusError::Unimplemented("Hybrid s3 cannot concat files.".into()).into()) | ||
} | ||
|
||
async fn remove_file(&self, file_info: &FileInfo) -> anyhow::Result<()> { | ||
async fn remove_file(&self, file_info: &FileInfo) -> RustusResult<()> { | ||
Check failure on line 176 in src/data_storage/s3_hybrid.rs GitHub Actions / clippyfunctions in traits cannot be declared `async`
|
||
if Some(file_info.offset) == file_info.length { | ||
self.bucket | ||
.delete_object(self.get_s3_key(file_info)) | ||
|