Skip to content

Commit

Permalink
chore: clippy cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
benluelo committed Nov 24, 2024
1 parent d12cb1a commit d6b64b2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
47 changes: 23 additions & 24 deletions mpc/client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ async fn wait_successful(latest_status: Arc<RwLock<Status>>) {
}

async fn create_temp_dir(contributor_id: &str) -> Result<(), DynError> {
if let Err(_) = tokio::fs::metadata(temp_dir(contributor_id)).await {
if tokio::fs::metadata(temp_dir(contributor_id)).await.is_err() {
tokio::fs::create_dir(temp_dir(contributor_id)).await?;
}
Ok(())
Expand All @@ -137,15 +137,12 @@ fn generate_pgp_key(email: String) -> SignedSecretKey {
.can_sign(true)
.can_encrypt(false)
.primary_user_id(email)
.preferred_symmetric_algorithms(
[SymmetricKeyAlgorithm::AES256].to_vec().try_into().unwrap(),
)
.preferred_hash_algorithms([HashAlgorithm::None].to_vec().try_into().unwrap());
.preferred_symmetric_algorithms([SymmetricKeyAlgorithm::AES256].to_vec().into())
.preferred_hash_algorithms([HashAlgorithm::None].to_vec().into());
let secret_key_params = key_params.build().expect("impossible");
let secret_key = secret_key_params.generate().expect("impossible");
let passwd_fn = || String::new();
let signed_secret_key = secret_key.sign(passwd_fn).expect("impossible");
signed_secret_key
secret_key.sign(passwd_fn).expect("impossible")
}

async fn contribute(
Expand All @@ -168,7 +165,7 @@ async fn contribute(
return Ok(());
}
let pgp_secret_file = pgp_secret_file(&user_email);
let mut secret_key = if let Ok(_) = tokio::fs::metadata(&pgp_secret_file).await {
let secret_key = if tokio::fs::metadata(&pgp_secret_file).await.is_ok() {
SignedSecretKey::from_armor_single::<&[u8]>(
tokio::fs::read(&pgp_secret_file).await?.as_ref(),
)
Expand All @@ -195,7 +192,10 @@ async fn contribute(
// If the current payload is not present, wipe all cached contribution
// files. This is needed because if a user rejoin the queue after having
// contributed using the previous cursor, it may have changed.
if let Err(_) = tokio::fs::metadata(&temp_file(&contributor_id, &current_payload.id)).await {
if tokio::fs::metadata(&temp_file(&contributor_id, &current_payload.id))
.await
.is_err()
{
remove_temp_dir(&contributor_id).await?;
create_temp_dir(&contributor_id).await?;
}
Expand Down Expand Up @@ -256,13 +256,13 @@ async fn contribute(
&payload_id,
&hex::encode(phase2_contribution_hash),
),
&mut secret_key,
|| String::new(),
&secret_key,
String::new,
)
.expect("impossible");
let public_key = secret_key
.public_key()
.sign(&secret_key, || String::new())
.sign(&secret_key, String::new)
.expect("impossible")
.to_armored_bytes(ArmorOptions::default())
.expect("impossible");
Expand Down Expand Up @@ -290,10 +290,10 @@ async fn contribute(
pool.conn(|conn| {
conn.execute(
"CREATE TABLE IF NOT EXISTS resumable_upload (
location TEXT PRIMARY KEY NOT NULL,
create_at TIMESTAMPTZ NOT NULL DEFAULT(unixepoch()),
expire TIMSTAMPTZ NOT NULL
)",
location TEXT PRIMARY KEY NOT NULL,
create_at TIMESTAMPTZ NOT NULL DEFAULT(unixepoch()),
expire TIMSTAMPTZ NOT NULL
)",
(), // empty list of parameters.
)?;
Ok(())
Expand Down Expand Up @@ -356,8 +356,7 @@ async fn contribute(
.headers()
.get("Upload-Expires")
.ok_or(Error::HeaderNotFound("Upload-Expires".into()))?
.to_str()?
.into();
.to_str()?;
let expire = parse_http_date(expire)?;
let expire_timestamp = expire.duration_since(UNIX_EPOCH)?.as_secs();
let location_clone = location.clone();
Expand Down Expand Up @@ -470,7 +469,7 @@ async fn handle(
let pgp_secret_file = pgp_secret_file(&email);
let guard = latest_status.write().await;
let result = {
if let Err(_) = tokio::fs::metadata(&pgp_secret_file).await {
if tokio::fs::metadata(&pgp_secret_file).await.is_err() {
let secret_key = generate_pgp_key(email);
let secret_key_serialized = secret_key
.to_armored_bytes(ArmorOptions::default())
Expand All @@ -490,7 +489,7 @@ async fn handle(
.and_then(|x| x.strip_prefix("/"))
{
let pgp_secret_file = pgp_secret_file(email);
if let Err(_) = tokio::fs::metadata(&pgp_secret_file).await {
if tokio::fs::metadata(&pgp_secret_file).await.is_err() {
response_empty(hyper::StatusCode::NOT_FOUND)
} else {
let content = tokio::fs::read(&pgp_secret_file).await?;
Expand All @@ -507,15 +506,15 @@ async fn handle(
{
tx_status.send(Status::Initializing).expect("impossible");
tokio::spawn(async move {
let result = (|| async {
let result = async {
let whole_body = req.collect().await?.aggregate();
contribute(
tx_status.clone(),
serde_json::from_reader(whole_body.reader())?,
)
.await?;
Ok::<_, DynError>(())
})()
}
.await;
match result {
Ok(_) => {
Expand Down Expand Up @@ -586,7 +585,7 @@ async fn input_and_status_handling(
tokio::spawn(async move {
while let Ok(status) = rx_status.recv().await {
*latest_status.write().await = status.clone();
if let Err(_) = tx_ui_clone.send(ui::Event::NewStatus(status)) {
if tx_ui_clone.send(ui::Event::NewStatus(status)).is_err() {
break;
}
}
Expand All @@ -605,7 +604,7 @@ async fn input_and_status_handling(
};
}
if last_tick.elapsed() >= tick_rate {
if let Err(_) = tx_ui.send(ui::Event::Tick) {
if tx_ui.send(ui::Event::Tick).is_err() {
break;
}
last_tick = Instant::now();
Expand Down
4 changes: 2 additions & 2 deletions mpc/client/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ fn ui(f: &mut Frame, state: &UiState, throbber_state: &mut ThrobberState) {
let gauge = Gauge::default()
.gauge_style(Style::default().fg(Color::Cyan))
.ratio(*progress as f64 / 100.0);
if gauge_area.top().saturating_add(0 as u16) > area.bottom() {
if gauge_area.top().saturating_add(0_u16) > area.bottom() {
return;
}
f.render_widget(
gauge,
Rect {
x: gauge_area.left(),
y: gauge_area.top().saturating_add(0 as u16),
y: gauge_area.top().saturating_add(0_u16),
width: gauge_area.width,
height: 1,
},
Expand Down
1 change: 1 addition & 0 deletions mpc/coordinator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ enum Command {
}

#[derive(thiserror::Error, Debug, Clone)]
#[allow(clippy::enum_variant_names)]
enum Error {
#[error("current contributor not found.")]
ContributorNotFound,
Expand Down
8 changes: 4 additions & 4 deletions mpc/shared/src/supabase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl SupabaseMPCApi {
Ok(self
.client
.from("contribution_submitted")
.eq("id", &contributor_id)
.eq("id", contributor_id)
.select("id")
.execute()
.await?
Expand All @@ -106,7 +106,7 @@ impl SupabaseMPCApi {
Ok(self
.client
.from("queue")
.eq("id", &contributor_id)
.eq("id", contributor_id)
.select("payload_id")
.execute()
.await?
Expand Down Expand Up @@ -169,7 +169,7 @@ impl SupabaseMPCApi {
Ok(self
.client
.from("contribution_signature")
.eq("id", &contributor_id)
.eq("id", contributor_id)
.select("*")
.execute()
.await?
Expand Down Expand Up @@ -199,7 +199,7 @@ impl SupabaseMPCApi {
)]))
.build()?;
let state_path = payload_output;
let action = match get_state_file(&state_path).await {
let action = match get_state_file(state_path).await {
content if content.len() < CONTRIBUTION_SIZE => {
StateFileAction::Download(content.len())
}
Expand Down

0 comments on commit d6b64b2

Please sign in to comment.