Placate clippy
type: reform
This commit is contained in:
parent
61bbd3bad5
commit
452486a782
6
.github/workflows/build.yaml
vendored
6
.github/workflows/build.yaml
vendored
|
@ -79,13 +79,13 @@ jobs:
|
|||
cargo clippy --version
|
||||
|
||||
- name: Build
|
||||
run: cargo build --all --verbose
|
||||
run: cargo build --all
|
||||
|
||||
- name: Test
|
||||
run: cargo test --all --verbose
|
||||
run: cargo test --all
|
||||
|
||||
- name: Clippy
|
||||
run: cargo clippy --all
|
||||
run: cargo clippy --all-targets --all-features
|
||||
|
||||
- name: Lint
|
||||
if: matrix.os == 'macos-latest'
|
||||
|
|
|
@ -99,10 +99,7 @@ impl Changelog {
|
|||
|
||||
#[throws]
|
||||
pub(crate) fn render(&self, book: bool) -> String {
|
||||
let mut lines: Vec<String> = Vec::new();
|
||||
|
||||
lines.push("Changelog".into());
|
||||
lines.push("=========".into());
|
||||
let mut lines: Vec<String> = vec!["Changelog".into(), "=========".into()];
|
||||
|
||||
for release in &self.releases {
|
||||
lines.push("".into());
|
||||
|
|
|
@ -12,8 +12,7 @@ impl<R: Row> Table<R> {
|
|||
|
||||
impl<R: Row> Display for Table<R> {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
let mut rows = Vec::new();
|
||||
rows.push(R::header().to_vec());
|
||||
let mut rows = vec![R::header().to_vec()];
|
||||
|
||||
for row in &self.rows {
|
||||
rows.push(row.entries());
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
../../target/gen/book/changelog.md
|
2
justfile
2
justfile
|
@ -33,7 +33,7 @@ test:
|
|||
cargo test --all
|
||||
|
||||
clippy:
|
||||
cargo clippy --all
|
||||
cargo clippy --all-targets --all-features
|
||||
|
||||
fmt:
|
||||
cargo +nightly fmt --all
|
||||
|
|
|
@ -5,8 +5,8 @@ error_on_unformatted = true
|
|||
format_code_in_doc_comments = true
|
||||
format_macro_bodies = true
|
||||
format_strings = true
|
||||
imports_granularity = "Crate"
|
||||
max_width = 100
|
||||
merge_imports = true
|
||||
newline_style = "Unix"
|
||||
normalize_comments = true
|
||||
reorder_impl_items = true
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#![allow(clippy::unwrap_used)]
|
||||
|
||||
use crate::common::*;
|
||||
|
||||
use std::io::BufWriter;
|
||||
|
@ -39,7 +41,7 @@ impl Bench for HasherBench {
|
|||
|
||||
while written < TEMPFILE_BYTES {
|
||||
rand::thread_rng().fill_bytes(&mut bytes);
|
||||
writer.write(&bytes).unwrap();
|
||||
writer.write_all(&bytes).unwrap();
|
||||
written += bytes.len().into_u64();
|
||||
}
|
||||
|
||||
|
|
|
@ -214,7 +214,7 @@ mod tests {
|
|||
("1kib", KI),
|
||||
("1KiB", KI),
|
||||
("12kib", 12 * KI),
|
||||
("1.5mib", 1 * MI + 512 * KI),
|
||||
("1.5mib", MI + 512 * KI),
|
||||
];
|
||||
|
||||
for (text, value) in CASES {
|
||||
|
|
|
@ -22,11 +22,11 @@ impl FileError {
|
|||
let metadata = match path.metadata() {
|
||||
Ok(metadata) => metadata,
|
||||
Err(error) => {
|
||||
if error.kind() == io::ErrorKind::NotFound {
|
||||
return Err(FileError::Missing);
|
||||
return Err(if error.kind() == io::ErrorKind::NotFound {
|
||||
FileError::Missing
|
||||
} else {
|
||||
return Err(FileError::Io(error));
|
||||
}
|
||||
FileError::Io(error)
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -56,11 +56,7 @@ impl FilePath {
|
|||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn from_components(components: &[&str]) -> FilePath {
|
||||
let components: Vec<String> = components
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(|component| component.to_owned())
|
||||
.collect();
|
||||
let components: Vec<String> = components.iter().cloned().map(ToOwned::to_owned).collect();
|
||||
assert!(!components.is_empty());
|
||||
FilePath { components }
|
||||
}
|
||||
|
|
|
@ -62,9 +62,9 @@ impl From<Sha1Digest> for Infohash {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Sha1Digest> for Infohash {
|
||||
fn into(self) -> Sha1Digest {
|
||||
self.inner
|
||||
impl From<Infohash> for Sha1Digest {
|
||||
fn from(infohash: Infohash) -> Sha1Digest {
|
||||
infohash.inner
|
||||
}
|
||||
}
|
||||
|
||||
|
|
14
src/lib.rs
14
src/lib.rs
|
@ -1,6 +1,7 @@
|
|||
#![deny(clippy::all, clippy::pedantic, clippy::restriction)]
|
||||
#![allow(
|
||||
clippy::blanket_clippy_restriction_lints,
|
||||
clippy::create_dir,
|
||||
clippy::else_if_without_else,
|
||||
clippy::enum_glob_use,
|
||||
clippy::float_arithmetic,
|
||||
|
@ -13,6 +14,7 @@
|
|||
clippy::map_unwrap_or,
|
||||
clippy::missing_docs_in_private_items,
|
||||
clippy::missing_inline_in_public_items,
|
||||
clippy::module_name_repetitions,
|
||||
clippy::needless_lifetimes,
|
||||
clippy::needless_pass_by_value,
|
||||
clippy::non_ascii_literal,
|
||||
|
@ -24,6 +26,18 @@
|
|||
clippy::wildcard_enum_match_arm,
|
||||
clippy::wildcard_imports
|
||||
)]
|
||||
#![cfg_attr(
|
||||
any(test),
|
||||
allow(
|
||||
clippy::blacklisted_name,
|
||||
clippy::expect_fun_call,
|
||||
clippy::expect_used,
|
||||
clippy::panic,
|
||||
clippy::panic_in_result_fn,
|
||||
clippy::unwrap_in_result,
|
||||
clippy::unwrap_used
|
||||
)
|
||||
)]
|
||||
|
||||
#[cfg(test)]
|
||||
#[macro_use]
|
||||
|
|
|
@ -86,7 +86,7 @@ impl MagnetLink {
|
|||
}
|
||||
|
||||
fn parse(text: &str) -> Result<Self, MagnetLinkParseError> {
|
||||
let url = Url::parse(&text).context(magnet_link_parse_error::URL)?;
|
||||
let url = Url::parse(&text).context(magnet_link_parse_error::Url)?;
|
||||
|
||||
if url.scheme() != "magnet" {
|
||||
return Err(MagnetLinkParseError::Scheme {
|
||||
|
@ -105,7 +105,7 @@ impl MagnetLink {
|
|||
}
|
||||
|
||||
let buf = hex::decode(infohash).context(magnet_link_parse_error::HexParse {
|
||||
text: infohash.to_string(),
|
||||
text: infohash.to_owned(),
|
||||
})?;
|
||||
|
||||
link = Some(MagnetLink::with_infohash(
|
||||
|
@ -270,7 +270,7 @@ mod tests {
|
|||
|
||||
assert_matches!(e, Error::MagnetLinkParse {
|
||||
text,
|
||||
source: MagnetLinkParseError::URL { .. },
|
||||
source: MagnetLinkParseError::Url { .. },
|
||||
} if text == link);
|
||||
}
|
||||
|
||||
|
@ -307,7 +307,7 @@ mod tests {
|
|||
text,
|
||||
source: MagnetLinkParseError::HexParse {
|
||||
text: ih,
|
||||
source: _,
|
||||
..
|
||||
}} if text == link && infohash == ih);
|
||||
}
|
||||
|
||||
|
@ -335,7 +335,7 @@ mod tests {
|
|||
text,
|
||||
source: MagnetLinkParseError::TrackerAddress {
|
||||
text: addr,
|
||||
source: _,
|
||||
..
|
||||
},
|
||||
} if text == link && addr == bad_addr);
|
||||
}
|
||||
|
@ -352,7 +352,7 @@ mod tests {
|
|||
text,
|
||||
source: MagnetLinkParseError::PeerAddress {
|
||||
text: addr,
|
||||
source: _,
|
||||
..
|
||||
}
|
||||
} if text == link && addr == bad_addr
|
||||
);
|
||||
|
|
|
@ -28,5 +28,5 @@ pub(crate) enum MagnetLinkParseError {
|
|||
source: url::ParseError,
|
||||
},
|
||||
#[snafu(display("Failed to parse URL: {}", source))]
|
||||
URL { source: url::ParseError },
|
||||
Url { source: url::ParseError },
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@ impl Md5Digest {
|
|||
|
||||
let mut bytes: [u8; 16] = [0; 16];
|
||||
|
||||
for n in 0..16 {
|
||||
for (n, byte) in bytes.iter_mut().enumerate() {
|
||||
let i = n * 2;
|
||||
bytes[n] = u8::from_str_radix(&hex[i..i + 2], 16).unwrap();
|
||||
*byte = u8::from_str_radix(&hex[i..i + 2], 16).unwrap();
|
||||
}
|
||||
|
||||
Self { bytes }
|
||||
|
|
16
src/shell.rs
16
src/shell.rs
|
@ -44,14 +44,14 @@ impl Shell {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<clap::Shell> for Shell {
|
||||
fn into(self) -> clap::Shell {
|
||||
match self {
|
||||
Self::Bash => clap::Shell::Bash,
|
||||
Self::Fish => clap::Shell::Fish,
|
||||
Self::Zsh => clap::Shell::Zsh,
|
||||
Self::Powershell => clap::Shell::PowerShell,
|
||||
Self::Elvish => clap::Shell::Elvish,
|
||||
impl From<Shell> for clap::Shell {
|
||||
fn from(shell: Shell) -> Self {
|
||||
match shell {
|
||||
Shell::Bash => clap::Shell::Bash,
|
||||
Shell::Fish => clap::Shell::Fish,
|
||||
Shell::Zsh => clap::Shell::Zsh,
|
||||
Shell::Powershell => clap::Shell::PowerShell,
|
||||
Shell::Elvish => clap::Shell::Elvish,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -387,7 +387,7 @@ impl Create {
|
|||
|
||||
let metainfo = Metainfo {
|
||||
comment: self.comment,
|
||||
encoding: Some(consts::ENCODING_UTF8.to_string()),
|
||||
encoding: Some(consts::ENCODING_UTF8.to_owned()),
|
||||
announce: self.announce.map(|url| url.to_string()),
|
||||
announce_list: if announce_list.is_empty() {
|
||||
None
|
||||
|
@ -1832,7 +1832,7 @@ Content Size 9 bytes
|
|||
|
||||
assert_matches!(
|
||||
metainfo.info.mode,
|
||||
Mode::Multiple { files } if files.len() == 0
|
||||
Mode::Multiple { files } if files.is_empty()
|
||||
);
|
||||
assert_eq!(metainfo.info.pieces, PieceList::new());
|
||||
Ok(())
|
||||
|
@ -2044,7 +2044,7 @@ Content Size 9 bytes
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn skip_hidden_attribute_dir_contents() -> Result<()> {
|
||||
fn skip_hidden_attribute_dir_contents() {
|
||||
let mut env = test_env! {
|
||||
args: [
|
||||
"torrent",
|
||||
|
@ -2065,7 +2065,7 @@ Content Size 9 bytes
|
|||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
env.write("foo/bar/baz", "baz");
|
||||
let path = env.resolve("foo/bar")?;
|
||||
let path = env.resolve("foo/bar").unwrap();
|
||||
Command::new("attrib")
|
||||
.arg("+h")
|
||||
.arg(&path)
|
||||
|
@ -2080,7 +2080,6 @@ Content Size 9 bytes
|
|||
Mode::Multiple { files } if files.is_empty()
|
||||
);
|
||||
assert_eq!(metainfo.info.pieces, PieceList::new());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2886,7 +2885,7 @@ Content Size 9 bytes
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn create_messages_path() -> Result<()> {
|
||||
fn create_messages_path() {
|
||||
let mut env = test_env! {
|
||||
args: [
|
||||
"torrent",
|
||||
|
@ -2901,20 +2900,17 @@ Content Size 9 bytes
|
|||
}
|
||||
};
|
||||
|
||||
let want = format!(
|
||||
"[1/3] \u{1F9FF} Searching `foo` for files…\n[2/3] \u{1F9EE} Hashing pieces…\n[3/3] \
|
||||
\u{1F4BE} Writing metainfo to `foo.torrent`…\n\u{2728}\u{2728} Done! \u{2728}\u{2728}\n",
|
||||
);
|
||||
let want = "[1/3] \u{1F9FF} Searching `foo` for files…\n[2/3] \u{1F9EE} Hashing \
|
||||
pieces…\n[3/3] \u{1F4BE} Writing metainfo to `foo.torrent`…\n\u{2728}\u{2728} \
|
||||
Done! \u{2728}\u{2728}\n";
|
||||
|
||||
env.assert_ok();
|
||||
|
||||
assert_eq!(env.err(), want);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_messages_subdir() -> Result<()> {
|
||||
fn create_messages_subdir() {
|
||||
let mut env = test_env! {
|
||||
args: [
|
||||
"torrent",
|
||||
|
@ -2940,12 +2936,10 @@ Content Size 9 bytes
|
|||
env.assert_ok();
|
||||
|
||||
assert_eq!(env.err(), want);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_messages_dot() -> Result<()> {
|
||||
fn create_messages_dot() {
|
||||
let mut env = test_env! {
|
||||
args: [
|
||||
"torrent",
|
||||
|
@ -2975,12 +2969,10 @@ Content Size 9 bytes
|
|||
);
|
||||
|
||||
assert_eq!(env.err(), want);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_messages_dot_dot() -> Result<()> {
|
||||
fn create_messages_dot_dot() {
|
||||
let mut env = test_env! {
|
||||
args: [
|
||||
"torrent",
|
||||
|
@ -3011,12 +3003,10 @@ Content Size 9 bytes
|
|||
);
|
||||
|
||||
assert_eq!(env.err(), want);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_messages_absolute() -> Result<()> {
|
||||
fn create_messages_absolute() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
|
||||
let input = dir.path().join("foo");
|
||||
|
@ -3051,12 +3041,10 @@ Content Size 9 bytes
|
|||
);
|
||||
|
||||
assert_eq!(env.err(), want);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_messages_stdio() -> Result<()> {
|
||||
fn create_messages_stdio() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
|
||||
let input = dir.path().join("foo");
|
||||
|
@ -3097,15 +3085,11 @@ Content Size 9 bytes
|
|||
}
|
||||
);
|
||||
|
||||
let want = format!(
|
||||
"[1/3] \u{1F9FF} Creating single-file torrent from standard input…\n[2/3] \u{1F9EE} Hashing \
|
||||
pieces…\n[3/3] \u{1F4BE} Writing metainfo to standard output…\n\u{2728}\u{2728} Done! \
|
||||
\u{2728}\u{2728}\n",
|
||||
);
|
||||
let want = "[1/3] \u{1F9FF} Creating single-file torrent from standard input…\n[2/3] \
|
||||
\u{1F9EE} Hashing pieces…\n[3/3] \u{1F4BE} Writing metainfo to standard \
|
||||
output…\n\u{2728}\u{2728} Done! \u{2728}\u{2728}\n";
|
||||
|
||||
assert_eq!(env.err(), want);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -158,6 +158,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn no_announce_flag() {
|
||||
const INFO: &str = "d6:lengthi0e4:name3:foo12:piece lengthi1e6:pieces0:e";
|
||||
|
||||
let mut env = test_env! {
|
||||
args: [
|
||||
"torrent",
|
||||
|
@ -172,8 +174,6 @@ mod tests {
|
|||
|
||||
env.assert_ok();
|
||||
|
||||
const INFO: &str = "d6:lengthi0e4:name3:foo12:piece lengthi1e6:pieces0:e";
|
||||
|
||||
let infohash = Sha1Digest::from_data(INFO.as_bytes());
|
||||
|
||||
assert_eq!(
|
||||
|
@ -184,6 +184,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn no_announce_positional() {
|
||||
const INFO: &str = "d6:lengthi0e4:name3:foo12:piece lengthi1e6:pieces0:e";
|
||||
|
||||
let mut env = test_env! {
|
||||
args: [
|
||||
"torrent",
|
||||
|
@ -197,8 +199,6 @@ mod tests {
|
|||
|
||||
env.assert_ok();
|
||||
|
||||
const INFO: &str = "d6:lengthi0e4:name3:foo12:piece lengthi1e6:pieces0:e";
|
||||
|
||||
let infohash = Sha1Digest::from_data(INFO.as_bytes());
|
||||
|
||||
assert_eq!(
|
||||
|
@ -209,6 +209,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn with_announce() {
|
||||
const INFO: &str = "d6:lengthi0e4:name3:foo12:piece lengthi1e6:pieces0:e";
|
||||
|
||||
let mut env = test_env! {
|
||||
args: [
|
||||
"torrent",
|
||||
|
@ -226,8 +228,6 @@ mod tests {
|
|||
|
||||
env.assert_ok();
|
||||
|
||||
const INFO: &str = "d6:lengthi0e4:name3:foo12:piece lengthi1e6:pieces0:e";
|
||||
|
||||
let infohash = Sha1Digest::from_data(INFO.as_bytes());
|
||||
|
||||
assert_eq!(
|
||||
|
@ -241,6 +241,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn unique_trackers() {
|
||||
const INFO: &str = "d6:lengthi0e4:name3:foo12:piece lengthi1e6:pieces0:e";
|
||||
|
||||
let mut env = test_env! {
|
||||
args: [
|
||||
"torrent",
|
||||
|
@ -259,8 +261,6 @@ mod tests {
|
|||
|
||||
env.assert_ok();
|
||||
|
||||
const INFO: &str = "d6:lengthi0e4:name3:foo12:piece lengthi1e6:pieces0:e";
|
||||
|
||||
let infohash = Sha1Digest::from_data(INFO.as_bytes());
|
||||
|
||||
assert_eq!(
|
||||
|
@ -271,8 +271,11 @@ mod tests {
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_peer() {
|
||||
const INFO: &str = "d6:lengthi0e4:name3:foo12:piece lengthi1e6:pieces0:e";
|
||||
|
||||
let mut env = test_env! {
|
||||
args: [
|
||||
"torrent",
|
||||
|
@ -292,8 +295,6 @@ mod tests {
|
|||
|
||||
env.assert_ok();
|
||||
|
||||
const INFO: &str = "d6:lengthi0e4:name3:foo12:piece lengthi1e6:pieces0:e";
|
||||
|
||||
let infohash = Sha1Digest::from_data(INFO.as_bytes());
|
||||
|
||||
assert_eq!(
|
||||
|
@ -307,6 +308,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn with_indices() {
|
||||
const INFO: &str = "d6:lengthi0e4:name3:foo12:piece lengthi1e6:pieces0:e";
|
||||
|
||||
let mut env = test_env! {
|
||||
args: [
|
||||
"torrent",
|
||||
|
@ -328,8 +331,6 @@ mod tests {
|
|||
|
||||
env.assert_ok();
|
||||
|
||||
const INFO: &str = "d6:lengthi0e4:name3:foo12:piece lengthi1e6:pieces0:e";
|
||||
|
||||
let infohash = Sha1Digest::from_data(INFO.as_bytes());
|
||||
|
||||
assert_eq!(
|
||||
|
@ -343,6 +344,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn infohash_correct_with_nonstandard_info_dict() {
|
||||
const INFO: &str = "d1:ai0e6:lengthi0e4:name3:foo12:piece lengthi1e6:pieces0:e";
|
||||
|
||||
let mut env = test_env! {
|
||||
args: [
|
||||
"torrent",
|
||||
|
@ -357,8 +360,6 @@ mod tests {
|
|||
|
||||
env.assert_ok();
|
||||
|
||||
const INFO: &str = "d1:ai0e6:lengthi0e4:name3:foo12:piece lengthi1e6:pieces0:e";
|
||||
|
||||
let infohash = Sha1Digest::from_data(INFO.as_bytes());
|
||||
|
||||
assert_eq!(
|
||||
|
|
|
@ -11,14 +11,12 @@ pub(crate) struct PieceLength {}
|
|||
#[allow(clippy::unused_self)]
|
||||
impl PieceLength {
|
||||
pub(crate) fn run(self, env: &mut Env) -> Result<(), Error> {
|
||||
let mut rows: Vec<(String, String, String, String)> = Vec::new();
|
||||
|
||||
rows.push((
|
||||
let mut rows: Vec<(String, String, String, String)> = vec![(
|
||||
"Content".into(),
|
||||
"Piece Length".into(),
|
||||
"Count".into(),
|
||||
"Piece List Size".into(),
|
||||
));
|
||||
)];
|
||||
|
||||
for i in 14..51 {
|
||||
let content_size = Bytes::from(1u64 << i);
|
||||
|
|
|
@ -462,6 +462,17 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn output_color() -> Result<()> {
|
||||
fn error(path: &str, message: &str) -> String {
|
||||
let style = Style::active();
|
||||
format!(
|
||||
"{}{}:{} {}",
|
||||
style.message().prefix(),
|
||||
path,
|
||||
style.message().suffix(),
|
||||
message,
|
||||
)
|
||||
}
|
||||
|
||||
let mut create_env = test_env! {
|
||||
args: [
|
||||
"torrent",
|
||||
|
@ -519,17 +530,6 @@ mod tests {
|
|||
|
||||
let style = Style::active();
|
||||
|
||||
fn error(path: &str, message: &str) -> String {
|
||||
let style = Style::active();
|
||||
format!(
|
||||
"{}{}:{} {}",
|
||||
style.message().prefix(),
|
||||
path,
|
||||
style.message().suffix(),
|
||||
message,
|
||||
)
|
||||
}
|
||||
|
||||
let want = [
|
||||
&format!(
|
||||
"{} \u{1F4BE} {}",
|
||||
|
@ -671,10 +671,8 @@ mod tests {
|
|||
|
||||
verify_env.assert_ok();
|
||||
|
||||
let want = format!(
|
||||
"[1/2] \u{1F4BE} Loading metainfo from standard input…\n[2/2] \u{1F9EE} Verifying pieces \
|
||||
from `foo`…\n\u{2728}\u{2728} Verification succeeded! \u{2728}\u{2728}\n",
|
||||
);
|
||||
let want = "[1/2] \u{1F4BE} Loading metainfo from standard input…\n[2/2] \u{1F9EE} Verifying \
|
||||
pieces from `foo`…\n\u{2728}\u{2728} Verification succeeded! \u{2728}\u{2728}\n";
|
||||
|
||||
assert_eq!(verify_env.err(), want);
|
||||
|
||||
|
|
|
@ -66,11 +66,10 @@ impl TestEnvBuilder {
|
|||
|
||||
let tempdir = self.tempdir.unwrap_or_else(|| tempfile::tempdir().unwrap());
|
||||
|
||||
let current_dir = if let Some(current_dir) = self.current_dir {
|
||||
tempdir.path().join(current_dir)
|
||||
} else {
|
||||
tempdir.path().to_owned()
|
||||
};
|
||||
let current_dir = self.current_dir.map_or_else(
|
||||
|| tempdir.path().to_owned(),
|
||||
|current_dir| tempdir.path().join(current_dir),
|
||||
);
|
||||
|
||||
let out_stream = OutputStream::new(
|
||||
Box::new(out.clone()),
|
||||
|
|
|
@ -177,7 +177,7 @@ impl TorrentSummary {
|
|||
|
||||
fn torrent_summary_data(&self) -> TorrentSummaryJson {
|
||||
let (file_count, files) = match &self.metainfo.info.mode {
|
||||
Mode::Single { .. } => (1, vec![self.metainfo.info.name.to_string()]),
|
||||
Mode::Single { .. } => (1, vec![self.metainfo.info.name.to_owned()]),
|
||||
Mode::Multiple { files } => (
|
||||
files.len(),
|
||||
files
|
||||
|
@ -197,7 +197,7 @@ impl TorrentSummary {
|
|||
};
|
||||
|
||||
TorrentSummaryJson {
|
||||
name: self.metainfo.info.name.to_string(),
|
||||
name: self.metainfo.info.name.to_owned(),
|
||||
comment: self.metainfo.comment.clone(),
|
||||
creation_date: self.metainfo.creation_date,
|
||||
created_by: self.metainfo.created_by.clone(),
|
||||
|
|
|
@ -36,17 +36,17 @@ impl<'a> Verifier<'a> {
|
|||
base: &'a Path,
|
||||
progress_bar: Option<ProgressBar>,
|
||||
) -> Result<Status> {
|
||||
Self::new(metainfo, base, progress_bar)?.verify_metainfo()
|
||||
Ok(Self::new(metainfo, base, progress_bar)?.verify_metainfo())
|
||||
}
|
||||
|
||||
fn verify_metainfo(mut self) -> Result<Status> {
|
||||
fn verify_metainfo(mut self) -> Status {
|
||||
match &self.metainfo.info.mode {
|
||||
Mode::Single { length, md5sum } => {
|
||||
self.hash(&self.base).ok();
|
||||
let error = FileError::verify(&self.base, *length, *md5sum).err();
|
||||
|
||||
let pieces = self.finish();
|
||||
Ok(Status::single(pieces, error))
|
||||
Status::single(pieces, error)
|
||||
}
|
||||
Mode::Multiple { files } => {
|
||||
let mut status = Vec::new();
|
||||
|
@ -65,7 +65,7 @@ impl<'a> Verifier<'a> {
|
|||
|
||||
let pieces = self.finish();
|
||||
|
||||
Ok(Status::multiple(pieces, status))
|
||||
Status::multiple(pieces, status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user