Skip to content

Commit

Permalink
cargo clippy whole repo
Browse files Browse the repository at this point in the history
  • Loading branch information
a-moreira committed Jul 6, 2023
1 parent 7ee645d commit e8f9924
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 49 deletions.
28 changes: 12 additions & 16 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@ use clap::{Args, CommandFactory, Parser, Subcommand};
use cli_clipboard::{ClipboardContext, ClipboardProvider};
use color_eyre::{eyre, eyre::Context};
use console::{style, Term};
use dialoguer::{Input};
use dialoguer::Input;
use futures::{future::Either, Future, FutureExt};
use indicatif::{MultiProgress, ProgressBar};
use magic_wormhole::PgpWordList;
use magic_wormhole::{forwarding, transfer, transit, Wormhole};
use std::{
io::Write,
path::{Path, PathBuf},
path::{PathBuf},
};

use std::{io::Write, path::PathBuf};

use magic_wormhole::{
dilated_transfer, forwarding, transfer, transit, MailboxConnection, Wormhole,
};
Expand Down Expand Up @@ -428,7 +425,7 @@ async fn main() -> eyre::Result<()> {
}
};

if with_dilation && peer_allows_dilation(&wormhole.peer_version()) {
if with_dilation && peer_allows_dilation(wormhole.peer_version()) {
log::debug!("dilate wormhole");
let mut dilated_wormhole = wormhole.dilate()?; // need to pass transit relay URL
dilated_wormhole.run().await;
Expand Down Expand Up @@ -1069,15 +1066,14 @@ async fn receive_inner_v1(
.truncate(true)
.open(&file_path)
.await?;
req
.accept(
&transit::log_transit_connection,
&mut file,
create_progress_handler(pb),
ctrl_c(),
)
.await
.context("Receive process failed")
req.accept(
&transit::log_transit_connection,
&mut file,
create_progress_handler(pb),
ctrl_c(),
)
.await
.context("Receive process failed")
}

async fn receive_inner_v2(
Expand Down Expand Up @@ -1117,7 +1113,7 @@ async fn receive_inner_v2(

/* Create a temporary directory for receiving */
use rand::Rng;
let tmp_dir = target_dir.join(&format!(
let tmp_dir = target_dir.join(format!(
"wormhole-tmp-{:06}",
rand::thread_rng().gen_range(0..1_000_000)
));
Expand Down
18 changes: 9 additions & 9 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::core::protocol::{WormholeProtocol, WormholeProtocolDefault};
#[cfg(feature = "dilation")]
use crate::dilation::DilatedWormhole;
use log::*;
use serde;

use serde_derive::{Deserialize, Serialize};
use serde_json::Value;
use xsalsa20poly1305 as secretbox;
Expand All @@ -18,7 +18,7 @@ pub mod rendezvous;
mod server_messages;
#[cfg(test)]
pub(crate) mod test;
mod wordlist;
pub mod wordlist;

#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
Expand Down Expand Up @@ -161,7 +161,7 @@ impl<V: serde::Serialize + Send + Sync + 'static> MailboxConnection<V> {
let (mut server, welcome) =
RendezvousServer::connect(&config.id, &config.rendezvous_url).await?;
let (nameplate, mailbox) = server.allocate_claim_open().await?;
let code = Code::new(&nameplate, &password);
let code = Code::new(&nameplate, password);

Ok(MailboxConnection {
config,
Expand Down Expand Up @@ -303,13 +303,13 @@ impl Wormhole {
) -> Result<(WormholeWelcome, Self), WormholeError> {
let mailbox_connection =
MailboxConnection::connect(config, code.clone(), !expect_claimed_nameplate).await?;
return Ok((
Ok((
WormholeWelcome {
welcome: mailbox_connection.welcome.clone(),
code: code,
code,
},
Self::connect(mailbox_connection).await?,
));
))
}

/// Set up a Wormhole which is the client-client part of the connection setup
Expand Down Expand Up @@ -469,7 +469,7 @@ impl Wormhole {
}

pub fn our_version(&self) -> &Box<dyn Any + Send + Sync> {
&self.protocol.our_version()
self.protocol.our_version()
}
}

Expand Down Expand Up @@ -643,7 +643,7 @@ impl<S: Into<String>> From<S> for EitherSide {

impl From<MySide> for TheirSide {
fn from(side: MySide) -> TheirSide {
TheirSide(side.0.into())
TheirSide(side.0)
}
}

Expand All @@ -660,7 +660,7 @@ impl Phase {
}

pub fn dilation(phase: u64) -> Self {
Phase(format!("dilate-{}", phase.to_string()).to_string().into())
Phase(format!("dilate-{}", phase).into())
}

pub fn is_version(&self) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions src/core/wordlist.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rand::{rngs::OsRng, seq::SliceRandom};
use serde_json::{self, Value};
use std::fmt;
use serde_json::{self};


use dialoguer::Completion;
use std::collections::HashMap;
Expand Down
10 changes: 5 additions & 5 deletions src/dilation/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ pub struct ManagerMachine {
#[cfg_attr(test, automock)]
impl ManagerMachine {
pub fn new(side: MySide) -> Self {
let machine = ManagerMachine {

ManagerMachine {
side,
role: Role::Follower,
state: Some(State::Wanting),
};
machine
}
}

pub fn current_state(&self) -> Option<State> {
Expand Down Expand Up @@ -96,7 +96,7 @@ impl ManagerMachine {
command = Some(ManagerCommand::from(ProtocolCommand::SendPlease {
side: side.clone(),
}));
let role = self.choose_role(&their_side.clone());
let role = self.choose_role(&their_side);
log::debug!(
"role: {}",
if role == Role::Leader {
Expand Down Expand Up @@ -184,7 +184,7 @@ impl ManagerMachine {
"processing event finished: state={}, command={}",
self.state.unwrap(),
command
.clone()

.map(|cmd| cmd.to_string())
.unwrap_or("n/a".to_string())
);
Expand Down
2 changes: 1 addition & 1 deletion src/dilation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl DilatedWormhole {
DilatedWormhole {
wormhole: WormholeConnection::new(wormhole),
side: side.clone(),
manager: ManagerMachine::new(side.clone()),
manager: ManagerMachine::new(side),
}
}

Expand Down
14 changes: 6 additions & 8 deletions src/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,13 +457,11 @@ impl<T> Offer<T> {
"{name} and {} other files or directories",
self.content.len() - 1
)
} else if self.is_directory() {
let count = entry.iter_files().count();
format!("{name} with {count} files inside")
} else {
if self.is_directory() {
let count = entry.iter_files().count();
format!("{name} with {count} files inside")
} else {
name.clone()
}
name.clone()
}
}

Expand Down Expand Up @@ -731,11 +729,11 @@ impl<T> OfferEntry<T> {
match self {
OfferEntry::RegularFile { size, .. } => OfferEntry::RegularFile {
size: *size,
content: f(&base_path),
content: f(base_path),
},
OfferEntry::Directory { content } => OfferEntry::Directory {
content: content
.into_iter()
.iter()
.map(|(k, v)| {
base_path.push(k.clone());
let v = v.set_content(base_path, f);
Expand Down
4 changes: 2 additions & 2 deletions src/transfer/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ pub async fn send_folder(
},
OfferSendEntry::RegularFile { size, content } => {
log::debug!("Adding file {path:?}; {size} bytes");
let header = tar_helper::create_header_file(&path, size)?;
let header = tar_helper::create_header_file(path, size)?;
let padding = tar_helper::padding(size);
*total_size += header.len() as u64;
*total_size += padding.len() as u64;
Expand Down Expand Up @@ -773,7 +773,7 @@ mod tar_helper {
// long name extension by emitting an entry which indicates that it's the
// filename.
if let Err(e) = header.set_path(path) {
let data = path2bytes(&path);
let data = path2bytes(path);
let max = header.as_old().name.len();
// Since `e` isn't specific enough to let us know the path is indeed too
// long, verify it first before using the extension.
Expand Down
12 changes: 6 additions & 6 deletions src/transfer/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async fn make_transit(
/* Send our transit hints */
wormhole
.send_json(&PeerMessage::transit_v2(
(**connector.our_hints()).clone().into(),
(**connector.our_hints()).clone(),
))
.await?;

Expand All @@ -118,7 +118,7 @@ async fn make_transit(
match wormhole.receive_json::<PeerMessage>().await??.check_err()? {
PeerMessage::TransitV2(transit) => {
debug!("received transit message: {:?}", transit);
transit.hints_v2.into()
transit.hints_v2
},
other => {
let error = TransferError::unexpected_message("transit-v2", other);
Expand Down Expand Up @@ -210,8 +210,8 @@ async fn send_inner(
) -> Result<(), TransferError> {
transit.send_record(&{
/* This must be split into two statements to appease the borrow checker (unfortunate side effect of borrow-through) */
let message = PeerMessageV2::Offer((&offer).into()).ser_msgpack();
message

PeerMessageV2::Offer((&offer).into()).ser_msgpack()
}).await?;

let files = match PeerMessageV2::de_msgpack(&transit.receive_record().await?)?.check_err()? {
Expand Down Expand Up @@ -246,7 +246,7 @@ async fn send_inner(
{
let offset = *offset;
/* This must be split into two statements to appease the borrow checker (unfortunate side effect of borrow-through) */
let content = (offer.get_file(&file).unwrap().0)();
let content = (offer.get_file(file).unwrap().0)();
let mut content = content.await?;
let file = file.clone();

Expand Down Expand Up @@ -591,7 +591,7 @@ async fn receive_inner(
PeerMessageV2::TransferAck(transfer_ack) => transfer_ack,
PeerMessageV2::FileStart(_) => {
bail!(TransferError::Protocol(
format!("Unexpected message: got 'file-start' but did not expect any more files")
"Unexpected message: got 'file-start' but did not expect any more files".to_string()
.into_boxed_str()
))
},
Expand Down

0 comments on commit e8f9924

Please sign in to comment.