Skip to content

Commit

Permalink
chore: appease clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
ccrutchf committed Dec 1, 2024
1 parent ca5a724 commit ab9cfc8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
16 changes: 8 additions & 8 deletions src/credential_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -118,7 +118,7 @@ impl CredentialManager {
totp_comand_encrypted: row.get(1)?,
totp_nonce: row.get(2)?
})
})?.filter_map(|r| r.ok()).collect::<Vec<DatabaseCredential>>().try_into()?;
})?.filter_map(|r| r.ok()).collect::<Vec<DatabaseCredential>>();

debug!(count=rows.len(), "Found user rows.");
Ok(rows)
Expand All @@ -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]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -263,7 +263,7 @@ impl CredentialManager {
let padded_password = self.pad_string(credential.password.as_str());
let key: &Key<Aes256Gcm> = 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())?;

Expand Down
2 changes: 1 addition & 1 deletion src/git_lfs/git_lfs_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}

Expand Down
5 changes: 1 addition & 4 deletions src/subcommands/login_subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
};
Expand Down
10 changes: 5 additions & 5 deletions src/subcommands/main_subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -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());

Expand Down Expand Up @@ -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.")?;
Expand All @@ -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(())
Expand Down
9 changes: 5 additions & 4 deletions src/synology_api/file_station.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, &parameters).await?)
self.get("SYNO.FileStation.CreateFolder", "create", 2, &parameters).await
}

#[tracing::instrument]
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<TProgressReporter: ProgressReporter + 'static>(&self,
source_file_path: &Path,
Expand Down

0 comments on commit ab9cfc8

Please sign in to comment.