From 201c8a4e7bf81ad703fb1f76691286250fc797e3 Mon Sep 17 00:00:00 2001 From: quexeky Date: Mon, 4 Nov 2024 17:48:44 +1100 Subject: [PATCH] Ran cargo clippy and cargo fmt Signed-off-by: quexeky --- src-tauri/src/downloads/download_agent.rs | 14 ++++++++------ src-tauri/src/downloads/download_commands.rs | 6 +++--- src-tauri/src/downloads/download_logic.rs | 17 ++++++++++++----- src-tauri/src/downloads/progress.rs | 8 ++++---- src-tauri/src/lib.rs | 3 ++- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src-tauri/src/downloads/download_agent.rs b/src-tauri/src/downloads/download_agent.rs index 43f6322..cae4a83 100644 --- a/src-tauri/src/downloads/download_agent.rs +++ b/src-tauri/src/downloads/download_agent.rs @@ -10,7 +10,7 @@ use rustix::fs::{fallocate, FallocateFlags}; use serde::{Deserialize, Serialize}; use std::fs::{create_dir_all, File}; use std::path::Path; -use std::sync::atomic::{AtomicBool, AtomicUsize}; +use std::sync::atomic::AtomicBool; use std::sync::{Arc, Mutex}; use urlencoding::encode; @@ -60,7 +60,7 @@ impl GameDownloadAgent { Box::new(download_logic::download_game_chunk), Arc::new(RelaxedCounter::new(0)), callback, - 0 + 0, ), contexts: Mutex::new(Vec::new()), } @@ -121,16 +121,18 @@ impl GameDownloadAgent { } let manifest_download = response.json::().unwrap(); - let length = manifest_download.iter().map(|(_, chunk)| { - return chunk.lengths.iter().sum::(); - }).sum::(); + let length = manifest_download + .values() + .map(|chunk| { + return chunk.lengths.iter().sum::(); + }) + .sum::(); self.progress.set_capacity(length); if let Ok(mut manifest) = self.manifest.lock() { *manifest = Some(manifest_download) } else { return Err(GameDownloadError::System(SystemError::MutexLockFailed)); } - Ok(()) } diff --git a/src-tauri/src/downloads/download_commands.rs b/src-tauri/src/downloads/download_commands.rs index cb49237..064bc55 100644 --- a/src-tauri/src/downloads/download_commands.rs +++ b/src-tauri/src/downloads/download_commands.rs @@ -110,11 +110,11 @@ pub async fn stop_specific_game_download( #[tauri::command] pub async fn get_game_download_progress( state: tauri::State<'_, Mutex>, - game_id: String + game_id: String, ) -> Result { let lock = state.lock().unwrap(); let download_agent = lock.game_downloads.get(&game_id).unwrap(); let progress = download_agent.progress.get_progress_percentage(); info!("{}", progress); - return Ok(progress) -} \ No newline at end of file + Ok(progress) +} diff --git a/src-tauri/src/downloads/download_logic.rs b/src-tauri/src/downloads/download_logic.rs index b9b5f7f..121a844 100644 --- a/src-tauri/src/downloads/download_logic.rs +++ b/src-tauri/src/downloads/download_logic.rs @@ -10,7 +10,7 @@ use std::{ io::{self, BufWriter, Error, ErrorKind, Seek, SeekFrom, Write}, path::PathBuf, sync::{ - atomic::{AtomicBool, AtomicUsize, Ordering}, + atomic::{AtomicBool, Ordering}, Arc, }, }; @@ -20,7 +20,7 @@ pub struct DropFileWriter { file: File, hasher: Context, callback: Arc, - progress: Arc + progress: Arc, } impl DropFileWriter { fn new(path: PathBuf, callback: Arc, progress: Arc) -> Self { @@ -28,7 +28,7 @@ impl DropFileWriter { file: OpenOptions::new().write(true).open(path).unwrap(), hasher: Context::new(), callback, - progress + progress, } } fn finish(mut self) -> io::Result { @@ -63,7 +63,11 @@ impl Seek for DropFileWriter { self.file.seek(pos) } } -pub fn download_game_chunk(ctx: DropDownloadContext, callback: Arc, progress: Arc) { +pub fn download_game_chunk( + ctx: DropDownloadContext, + callback: Arc, + progress: Arc, +) { if callback.load(Ordering::Acquire) { info!("Callback stopped download at start"); return; @@ -111,7 +115,10 @@ pub fn download_game_chunk(ctx: DropDownloadContext, callback: Arc, } let file = match writer.into_inner() { Ok(file) => file, - Err(_) => {error!("Failed to acquire writer from BufWriter"); return; } + Err(_) => { + error!("Failed to acquire writer from BufWriter"); + return; + } }; let res = hex::encode(file.finish().unwrap().0); diff --git a/src-tauri/src/downloads/progress.rs b/src-tauri/src/downloads/progress.rs index e217f56..4511558 100644 --- a/src-tauri/src/downloads/progress.rs +++ b/src-tauri/src/downloads/progress.rs @@ -1,7 +1,7 @@ use atomic_counter::{AtomicCounter, RelaxedCounter}; use log::info; use rayon::ThreadPoolBuilder; -use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; +use std::sync::atomic::AtomicBool; use std::sync::{Arc, Mutex}; pub struct ProgressChecker @@ -11,7 +11,7 @@ where counter: Arc, f: Arc, Arc) + Send + Sync + 'static>>, callback: Arc, - capacity: Mutex + capacity: Mutex, } impl ProgressChecker @@ -22,13 +22,13 @@ where f: Box, Arc) + Send + Sync + 'static>, counter: Arc, callback: Arc, - capacity: usize + capacity: usize, ) -> Self { Self { f: f.into(), counter, callback, - capacity: capacity.into() + capacity: capacity.into(), } } pub fn run_contexts_sequentially(&self, contexts: Vec) { diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index a64595a..c8806ef 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -11,7 +11,8 @@ use crate::downloads::download_agent::GameDownloadAgent; use auth::{auth_initiate, generate_authorization_header, recieve_handshake}; use db::{DatabaseInterface, DATA_ROOT_DIR}; use downloads::download_commands::{ - get_game_download_progress, queue_game_download, start_game_downloads, stop_specific_game_download + get_game_download_progress, queue_game_download, start_game_downloads, + stop_specific_game_download, }; use env_logger::Env; use http::{header::*, response::Builder as ResponseBuilder};