diff --git a/src/credential_manager.rs b/src/credential_manager.rs index fc533af..a7e4935 100644 --- a/src/credential_manager.rs +++ b/src/credential_manager.rs @@ -81,8 +81,8 @@ impl CredentialManager { #[tracing::instrument] fn clean_url(&self, url: &str) -> String { - if url.ends_with("/") { - return url[..url.len() - 1].to_string(); + if let Some(url) = url.strip_suffix("/") { + return url.to_string(); } return url.to_string(); @@ -118,7 +118,7 @@ impl CredentialManager { totp_comand_encrypted: row.get(1)?, totp_nonce: row.get(2)? }) - })?.filter_map(|r| r.ok()).collect::>().try_into()?; + })?.filter_map(|r| r.ok()).collect::>(); debug!(count=rows.len(), "Found user rows."); Ok(rows) @@ -145,16 +145,16 @@ impl CredentialManager { #[tracing::instrument] fn get_entry(&mut self, url: &str, user: &str) -> Result<&Entry>{ - if !self.entry_cache.contains_key(&(url.to_string(), user.to_string())) { + if let std::collections::hash_map::Entry::Vacant(e) = self.entry_cache.entry((url.to_string(), user.to_string())) { debug!(user=user, url=url, "Entry did not exist in cache."); info!("Creating entry."); let entry = Entry::new(url, user)?; - self.entry_cache.insert((url.to_string(), user.to_string()), entry); + e.insert(entry); } info!("Returning entry from cache."); - Ok(self.entry_cache.get(&(url.to_string(), user.to_string())).context("Entry does not exist in cache")?) + self.entry_cache.get(&(url.to_string(), user.to_string())).context("Entry does not exist in cache") } #[tracing::instrument] @@ -195,7 +195,7 @@ impl CredentialManager { let nonce_vec = database_credential.totp_nonce.clone().context("No nonce provided for credential")?; - let cipher = Aes256Gcm::new(&key); + let cipher = Aes256Gcm::new(key); let nonce = Nonce::from_iter(nonce_vec); let plaintext = cipher.decrypt( &nonce, @@ -263,7 +263,7 @@ impl CredentialManager { let padded_password = self.pad_string(credential.password.as_str()); let key: &Key = padded_password.as_bytes().into(); - let cipher = Aes256Gcm::new(&key); + let cipher = Aes256Gcm::new(key); let nonce = Aes256Gcm::generate_nonce(&mut OsRng); // 96-bits; unique per message let ciphertext = cipher.encrypt(&nonce, credential.totp_command.clone().context("TOTP Command does not exist.")?.as_bytes())?; diff --git a/src/git_lfs/git_lfs_parser.rs b/src/git_lfs/git_lfs_parser.rs index 33e5b6a..d07550f 100644 --- a/src/git_lfs/git_lfs_parser.rs +++ b/src/git_lfs/git_lfs_parser.rs @@ -146,7 +146,7 @@ impl<'custom_transfer_agent, T: CustomTransferAgent> GitLfsParser<'custom_transf event: event_type, oid: event.oid.clone(), path: event.path.clone(), - size: event.size.clone() + size: event.size }) } diff --git a/src/subcommands/login_subcommand.rs b/src/subcommands/login_subcommand.rs index d6484eb..33677b9 100644 --- a/src/subcommands/login_subcommand.rs +++ b/src/subcommands/login_subcommand.rs @@ -34,10 +34,7 @@ impl Subcommand for LoginSubcommand { let totp_command = match totp_command { Some(totp_command) => Some(totp_command.clone()), None => match credential_ref { - Some(credential) => match credential.totp_command { - Some(totp_command) => Some(totp_command), - None => None - }, + Some(credential) => credential.totp_command, None => None } }; diff --git a/src/subcommands/main_subcommand.rs b/src/subcommands/main_subcommand.rs index ad11f15..4b4f920 100644 --- a/src/subcommands/main_subcommand.rs +++ b/src/subcommands/main_subcommand.rs @@ -32,7 +32,7 @@ impl CustomTransferAgent for MainSubcommand { let oid = event.oid.clone().context("OID should not be null")?; let git_lfs_progress_reporter = GitLfsProgressReporter::new( - event.size.clone().context("Size should not be null")?, + event.size.context("Size should not be null")?, event.oid.clone().context("oid should not be null")?); let source_file_path = format!( @@ -48,8 +48,8 @@ impl CustomTransferAgent for MainSubcommand { target_directory_path.push(".git"); target_directory_path.push("lfs"); target_directory_path.push("objects"); - target_directory_path.push(oid[..2].to_string()); - target_directory_path.push(oid[2..4].to_string()); + target_directory_path.push(&oid[..2]); + target_directory_path.push(&oid[2..4]); info!("Target path is \"{}\".", target_directory_path.as_os_str().to_string_lossy()); @@ -105,7 +105,7 @@ impl CustomTransferAgent for MainSubcommand { let configuration = Configuration::load()?; let git_lfs_progress_reporter = GitLfsProgressReporter::new( - event.size.clone().context("Size should not be null")?, + event.size.context("Size should not be null")?, event.oid.clone().context("oid should not be null")?); let source_path = event.path.clone().context("Path should not be null.")?; @@ -118,7 +118,7 @@ impl CustomTransferAgent for MainSubcommand { let source_path = Path::new(source_path.as_str()); let file_station = self.file_station.clone().context("File Station should not be null")?; - file_station.upload(source_path, event.size.clone().context("Size should not be null")?, configuration.path.as_str(), false, false, None, None, None, Some(progress_reporter)).await?; + file_station.upload(source_path, event.size.context("Size should not be null")?, configuration.path.as_str(), false, false, None, None, None, Some(progress_reporter)).await?; info!("Upload finished."); Ok(()) diff --git a/src/synology_api/file_station.rs b/src/synology_api/file_station.rs index df91f99..41b8892 100644 --- a/src/synology_api/file_station.rs +++ b/src/synology_api/file_station.rs @@ -135,7 +135,7 @@ impl SynologyFileStation { parameters.insert("name", name); parameters.insert("force_parent", force_parent_string.as_str()); - Ok(self.get("SYNO.FileStation.CreateFolder", "create", 2, ¶meters).await?) + self.get("SYNO.FileStation.CreateFolder", "create", 2, ¶meters).await } #[tracing::instrument] @@ -172,15 +172,15 @@ impl SynologyFileStation { while let Ok(chunk) = response.chunk().await { if let Some(chunk) = chunk { + let write_len = target_stream.write(&chunk).await?; + if let Some(progress_reporter) = &mut progress_reporter { - let result = progress_reporter.update(chunk.len()); + let result = progress_reporter.update(write_len); if let Err(error) = result { warn!("An error occurred reporting progress: \"{error}\"."); } } - - target_stream.write(&chunk).await?; } else { break; @@ -278,6 +278,7 @@ impl SynologyFileStation { } } + #[allow(clippy::too_many_arguments)] // Allow this so that we better match the Synology API. #[tracing::instrument] pub async fn upload(&self, source_file_path: &Path,