Configure clippy and lint on push

Enable as many lints as I can stand. I'll definitely add more exceptions as
`clippy::pedantic` and `clippy::restriction` wear me down.

type: testing
This commit is contained in:
Casey Rodarmor 2020-01-04 18:58:42 -08:00
parent 7f630a1bd9
commit 9f83661374
No known key found for this signature in database
GPG Key ID: 556186B153EC6FE0
21 changed files with 285 additions and 166 deletions

View File

@ -7,7 +7,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Update
run: rustup update stable
- name: Version
run: |
rustup --version
cargo --version
cargo clippy --version
- name: Build
run: cargo build --verbose
- name: Test
run: cargo test --verbose
- name: Lint
run: cargo clippy

166
Cargo.lock generated
View File

@ -13,22 +13,21 @@ name = "ansi_term"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "atty"
version = "0.2.11"
version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
"termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "1.0.4"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -50,11 +49,11 @@ version = "2.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -78,7 +77,7 @@ name = "heck"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -103,7 +102,8 @@ dependencies = [
"serde_bytes 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
"sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"snafu 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"static_assertions 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
@ -134,11 +134,6 @@ name = "memchr"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "numtoa"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "percent-encoding"
version = "2.1.0"
@ -151,17 +146,31 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "proc-macro-error"
version = "0.2.6"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro-error-attr 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
"rustversion 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "proc-macro-error-attr"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rustversion 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
"syn-mid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "proc-macro2"
version = "1.0.6"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -172,7 +181,7 @@ name = "quote"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -214,17 +223,9 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.1.54"
version = "0.1.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "redox_termios"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex"
version = "1.3.1"
@ -246,7 +247,17 @@ name = "remove_dir_all"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustversion"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -295,9 +306,9 @@ name = "serde_derive"
version = "1.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -324,11 +335,16 @@ name = "snafu-derive"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "strsim"
version = "0.8.0"
@ -336,35 +352,45 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "structopt"
version = "0.3.5"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt-derive 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt-derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "structopt-derive"
version = "0.3.5"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro-error 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro-error 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syn"
version = "1.0.11"
version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syn-mid"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "tempfile"
version = "3.1.0"
@ -373,20 +399,9 @@ dependencies = [
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)",
"remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "termion"
version = "1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
"numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -394,7 +409,7 @@ name = "textwrap"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -423,12 +438,12 @@ dependencies = [
[[package]]
name = "unicode-segmentation"
version = "1.3.0"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-width"
version = "0.1.5"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -457,7 +472,7 @@ version = "2.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -468,7 +483,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi"
version = "0.3.7"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -485,7 +500,7 @@ name = "winapi-util"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -496,8 +511,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d"
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
"checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90"
"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
"checksum c2-chacha 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "214238caa1bf3a496ec3392968969cab8549f96ff30652c9e56885329315f6bb"
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
@ -510,21 +525,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
"checksum md5 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771"
"checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e"
"checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
"checksum percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
"checksum ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b"
"checksum proc-macro-error 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "aeccfe4d5d8ea175d5f0e4a2ad0637e0f4121d63bd99d356fb1f39ab2e7c6097"
"checksum proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9c9e470a8dc4aeae2dee2f335e8f533e2d4b347e1434e5671afc49b054592f27"
"checksum proc-macro-error 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "53c98547ceaea14eeb26fcadf51dc70d01a2479a7839170eae133721105e4428"
"checksum proc-macro-error-attr 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c2bf5d493cf5d3e296beccfd61794e445e830dfc8070a9c248ad3ee071392c6c"
"checksum proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "0319972dcae462681daf4da1adeeaa066e3ebd29c69be96c6abb1259d2ee2bcc"
"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
"checksum rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3ae1b169243eaf61759b8475a998f0a385e42042370f3a7dbaf35246eacc8412"
"checksum rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853"
"checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
"checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
"checksum redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)" = "12229c14a0f65c4f1cb046a3b52047cdd9da1f4b30f8a39c5063c8bae515e252"
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
"checksum regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dc220bd33bdce8f093101afe22a037b8eb0e5af33592e6a9caafff0d4cb81cbd"
"checksum regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716"
"checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e"
"checksum rustversion 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a0538bd897e17257b0128d2fd95c2ed6df939374073a36166051a79e2eb7986"
"checksum same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "585e8ddcedc187886a30fa705c47985c3fa88d06624095856b36ca0b82ff4421"
"checksum serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449"
"checksum serde_bencode 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b79ce11369638af2fea08e00390316304c5b5e1b7a53d58ace925152b657443"
@ -535,24 +550,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum smallvec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44e59e0c9fa00817912ae6e4e6e3c4fe04455e75699d06eedc7d85917ed8e8f4"
"checksum snafu 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "41207ca11f96a62cd34e6b7fdf73d322b25ae3848eb9d38302169724bb32cf27"
"checksum snafu-derive 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4c5e338c8b0577457c9dda8e794b6ad7231c96e25b1b0dd5842d52249020c1c0"
"checksum static_assertions 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
"checksum structopt 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "30b3a3e93f5ad553c38b3301c8a0a0cec829a36783f6a0c467fc4bf553a5f5bf"
"checksum structopt-derive 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea692d40005b3ceba90a9fe7a78fa8d4b82b0ce627eebbffc329aab850f3410e"
"checksum syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "dff0acdb207ae2fe6d5976617f887eb1e35a2ba52c13c7234c790960cdad9238"
"checksum structopt 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "884ae79d6aad1e738f4a70dff314203fd498490a63ebc4d03ea83323c40b7b72"
"checksum structopt-derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0a97f829a34a0a9d5b353a881025a23b8c9fd09d46be6045df6b22920dbd7a93"
"checksum syn 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1e4ff033220a41d1a57d8125eab57bf5263783dfdcc18688b1dacc6ce9651ef8"
"checksum syn-mid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9fd3937748a7eccff61ba5b90af1a20dbf610858923a9192ea0ecb0cb77db1d0"
"checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9"
"checksum termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dde0593aeb8d47accea5392b39350015b5eccb12c0d98044d856983d89548dea"
"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
"checksum unicode-normalization 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b561e267b2326bb4cebfc0ef9e68355c7abe6c6f522aeac2f5bf95d56c59bdcf"
"checksum unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1967f4cdfc355b37fd76d2a954fb2ed3871034eb4f26d60537d88795cfc332a9"
"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"
"checksum unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"
"checksum unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479"
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
"checksum url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75b414f6c464c879d7f9babf951f23bc3743fb7313c081b2e6ca719067ea9d61"
"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
"checksum walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9658c94fa8b940eab2250bd5a457f9c48b748420d71293b165c8cdbe2f55f71e"
"checksum wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d"
"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770"
"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View File

@ -23,6 +23,7 @@ structopt = "0.3"
tempfile = "3"
url = "2"
walkdir = "2"
static_assertions = "1.1.0"
[dependencies.serde]
version = "1"

View File

@ -17,6 +17,13 @@ done BRANCH:
git diff --no-ext-diff --quiet --exit-code {{BRANCH}}
git branch -D {{BRANCH}}
test:
cargo test
# lint code
lint:
cargo clippy
# retrieve large collection of torrents from the Internet Archive
get-torrents:
aria2c \

View File

@ -153,7 +153,7 @@ impl<'buffer> Parser<'buffer> {
Ok(&self.buffer[start..self.index])
}
fn parse_digits(&mut self, digits: &[u8]) -> Result<u64, Error> {
fn parse_digits(digits: &[u8]) -> Result<u64, Error> {
if digits.is_empty() {
return Err(EmptyInteger);
}
@ -190,7 +190,7 @@ impl<'buffer> Parser<'buffer> {
self.expect(b'e')?;
let value = self.parse_digits(digits)?;
let value = Self::parse_digits(digits)?;
if value == 0 && negative {
return Err(NegativeZero);
@ -250,7 +250,7 @@ impl<'buffer> Parser<'buffer> {
self.expect(b':')?;
let len = self.parse_digits(digits)?;
let len = Self::parse_digits(digits)?;
let start = self.index;
for _ in 0..len {

View File

@ -3,6 +3,7 @@ pub(crate) use std::{
borrow::Cow,
cmp::{Ordering, Reverse},
collections::{BTreeMap, HashMap},
convert::TryInto,
env,
ffi::{OsStr, OsString},
fmt::{self, Display, Formatter},
@ -12,7 +13,7 @@ pub(crate) use std::{
path::{Path, PathBuf},
process, str,
time::{SystemTime, SystemTimeError},
u64, usize,
usize,
};
// dependencies
@ -21,6 +22,7 @@ pub(crate) use regex::{Regex, RegexSet};
pub(crate) use serde::{Deserialize, Serialize};
pub(crate) use sha1::Sha1;
pub(crate) use snafu::{ResultExt, Snafu};
pub(crate) use static_assertions::const_assert;
pub(crate) use structopt::StructOpt;
pub(crate) use url::Url;
pub(crate) use walkdir::WalkDir;
@ -29,7 +31,9 @@ pub(crate) use walkdir::WalkDir;
pub(crate) use crate::{bencode, consts, error, torrent};
// traits
pub(crate) use crate::{path_ext::PathExt, reckoner::Reckoner};
pub(crate) use crate::{
into_u64::IntoU64, into_usize::IntoUsize, path_ext::PathExt, reckoner::Reckoner,
};
// structs and enums
pub(crate) use crate::{

View File

@ -3,32 +3,32 @@ use crate::common::*;
pub(crate) struct Environment {
args: Vec<String>,
dir: Box<dyn AsRef<Path>>,
err: Box<dyn Write>,
pub(crate) err: Box<dyn Write>,
}
impl Environment {
pub(crate) fn main() -> Environment {
pub(crate) fn main() -> Self {
let dir = match env::current_dir() {
Ok(dir) => dir,
Err(error) => panic!("Failed to get current directory: {}", error),
};
Environment::new(dir, io::stderr(), env::args())
Self::new(dir, io::stderr(), env::args())
}
pub(crate) fn run(&self) -> Result<(), Error> {
pub(crate) fn run(&mut self) -> Result<(), Error> {
Opt::from_iter_safe(&self.args)?.run(self)
}
pub(crate) fn new<D, E, S, I>(dir: D, err: E, args: I) -> Environment
pub(crate) fn new<D, E, S, I>(dir: D, err: E, args: I) -> Self
where
D: AsRef<Path> + 'static,
E: Write + 'static,
S: Into<String>,
I: IntoIterator<Item = S>,
{
Environment {
args: args.into_iter().map(|s| s.into()).collect(),
Self {
args: args.into_iter().map(Into::into).collect(),
dir: Box::new(dir),
err: Box::new(err),
}

8
src/err.rs Normal file
View File

@ -0,0 +1,8 @@
macro_rules! err {
($env:expr, $fmt:expr) => {
write!($env.err, $fmt).context(crate::error::Stderr)?;
};
($env:expr, $fmt:expr, $($arg:tt)*) => {
write!($env.err, $fmt, $($arg)*).context(crate::error::Stderr)?;
};
}

11
src/errln.rs Normal file
View File

@ -0,0 +1,11 @@
macro_rules! errln {
($env:expr) => {
writeln!($env.err, "").context(crate::error::Stderr)?;
};
($env:expr, $fmt:expr) => {
writeln!($env.err, $fmt).context(crate::error::Stderr)?;
};
($env:expr, $fmt:expr, $($arg:tt)*) => {
writeln!($env.err, $fmt, $($arg)*).context(crate::error::Stderr)?;
};
}

View File

@ -9,6 +9,8 @@ pub(crate) enum Error {
Clap { source: clap::Error },
#[snafu(display("I/O error at `{}`: {}", path.display(), source))]
Filesystem { source: io::Error, path: PathBuf },
#[snafu(display("Failed to write to standard error stream: {}", source))]
Stderr { source: io::Error },
#[snafu(display("Serialization failed: {}", source))]
Serialize { source: serde_bencode::Error },
#[snafu(display("Filename was not valid unicode: {}", filename.to_string_lossy()))]
@ -31,29 +33,29 @@ pub(crate) enum Error {
}
impl From<clap::Error> for Error {
fn from(source: clap::Error) -> Error {
Error::Clap { source }
fn from(source: clap::Error) -> Self {
Self::Clap { source }
}
}
impl From<serde_bencode::Error> for Error {
fn from(source: serde_bencode::Error) -> Error {
Error::Serialize { source }
fn from(source: serde_bencode::Error) -> Self {
Self::Serialize { source }
}
}
impl From<SystemTimeError> for Error {
fn from(source: SystemTimeError) -> Error {
Error::SystemTime { source }
fn from(source: SystemTimeError) -> Self {
Self::SystemTime { source }
}
}
impl From<walkdir::Error> for Error {
fn from(walkdir_error: walkdir::Error) -> Error {
fn from(walkdir_error: walkdir::Error) -> Self {
let path = walkdir_error.path().unwrap().to_owned();
if let Some(source) = walkdir_error.into_io_error() {
Error::Filesystem { source, path }
Self::Filesystem { source, path }
} else {
unreachable!("Encountered unexpected walkdir error")
}

View File

@ -5,7 +5,7 @@ pub(crate) struct Hasher {
length: u64,
md5sum: bool,
piece_bytes_hashed: u64,
piece_length: u64,
piece_length: u32,
pieces: Vec<u8>,
sha1: Sha1,
}
@ -14,14 +14,14 @@ impl Hasher {
pub(crate) fn hash(
root: &Path,
md5sum: bool,
piece_length: u64,
piece_length: u32,
) -> Result<(Mode, Vec<u8>), Error> {
Hasher::new(md5sum, piece_length).hash_root(root)
Self::new(md5sum, piece_length).hash_root(root)
}
fn new(md5sum: bool, piece_length: u64) -> Hasher {
Hasher {
buffer: vec![0; piece_length as usize],
fn new(md5sum: bool, piece_length: u32) -> Self {
Self {
buffer: vec![0; piece_length.into_usize()],
length: 0,
piece_bytes_hashed: 0,
pieces: Vec::new(),
@ -100,7 +100,10 @@ impl Hasher {
};
while remaining > 0 {
let to_buffer = self.buffer.len().min(remaining as usize);
let to_buffer: usize = remaining
.min(self.buffer.len().into_u64())
.try_into()
.unwrap();
let buffer = &mut self.buffer[0..to_buffer];
file.read_exact(buffer)?;
@ -110,7 +113,7 @@ impl Hasher {
self.piece_bytes_hashed += 1;
if self.piece_bytes_hashed == self.piece_length {
if self.piece_bytes_hashed == self.piece_length.into() {
self.pieces.extend(&self.sha1.digest().bytes());
self.sha1.reset();
self.piece_bytes_hashed = 0;

View File

@ -4,7 +4,7 @@ use crate::common::*;
pub struct Info {
pub private: u8,
#[serde(rename = "piece length")]
pub piece_length: u64,
pub piece_length: u32,
pub name: String,
#[serde(with = "serde_bytes")]
pub pieces: Vec<u8>,

16
src/into_u64.rs Normal file
View File

@ -0,0 +1,16 @@
use crate::common::*;
// Systems with pointers larger than 64 bits may eventually exist, but
// for now let's assume that usize is at most 32 bits, and document that
// assumption with this assert.
const_assert!(std::mem::size_of::<usize>() <= std::mem::size_of::<u64>());
pub(crate) trait IntoU64 {
fn into_u64(self) -> u64;
}
impl IntoU64 for usize {
fn into_u64(self) -> u64 {
self as u64
}
}

16
src/into_usize.rs Normal file
View File

@ -0,0 +1,16 @@
use crate::common::*;
// Intermodal, or at least parts of it, might eventually be ported to
// 16-bit systems, but for now let's assume that usize is at least 32
// bits, and document that assumption with this assert.
const_assert!(std::mem::size_of::<usize>() >= std::mem::size_of::<u32>());
pub(crate) trait IntoUsize {
fn into_usize(self) -> usize;
}
impl IntoUsize for u32 {
fn into_usize(self) -> usize {
self as usize
}
}

View File

@ -1,9 +1,29 @@
#![deny(clippy::all, clippy::pedantic, clippy::restriction)]
#![allow(
clippy::else_if_without_else,
clippy::enum_glob_use,
clippy::implicit_return,
clippy::indexing_slicing,
clippy::integer_arithmetic,
clippy::missing_docs_in_private_items,
clippy::option_map_unwrap_or_else,
clippy::option_unwrap_used,
clippy::result_expect_used,
clippy::result_unwrap_used
)]
use crate::common::*;
#[cfg(test)]
#[macro_use]
mod matches;
#[macro_use]
mod errln;
#[macro_use]
mod err;
#[cfg(test)]
mod testing;
@ -15,6 +35,8 @@ mod error;
mod file_info;
mod hasher;
mod info;
mod into_u64;
mod into_usize;
mod metainfo;
mod mode;
mod opt;

View File

@ -9,7 +9,7 @@ pub(crate) struct Opt {
}
impl Opt {
pub(crate) fn run(self, env: &Environment) -> Result<(), Error> {
pub(crate) fn run(self, env: &mut Environment) -> Result<(), Error> {
self.subcommand.run(env, self.unstable)
}
}

View File

@ -11,7 +11,7 @@ pub(crate) trait Reckoner<K> {
where
I: IntoIterator<Item = K>,
{
for k in i.into_iter() {
for k in i {
self.increment(k);
}
}

View File

@ -6,7 +6,7 @@ pub(crate) enum Subcommand {
}
impl Subcommand {
pub(crate) fn run(self, env: &Environment, unstable: bool) -> Result<(), Error> {
pub(crate) fn run(self, env: &mut Environment, unstable: bool) -> Result<(), Error> {
match self {
Self::Torrent(torrent) => torrent.run(env, unstable),
}

View File

@ -10,7 +10,7 @@ pub(crate) enum Torrent {
}
impl Torrent {
pub(crate) fn run(self, env: &Environment, unstable: bool) -> Result<(), Error> {
pub(crate) fn run(self, env: &mut Environment, unstable: bool) -> Result<(), Error> {
match self {
Self::Create(create) => create.run(env),
Self::Stats(stats) => stats.run(env, unstable),

View File

@ -15,7 +15,7 @@ pub(crate) struct Create {
#[structopt(name = "COMMENT", long = "comment")]
comment: Option<String>,
#[structopt(name = "PIECE-LENGTH", long = "piece-length", default_value = "524288")]
piece_length: u64,
piece_length: u32,
#[structopt(name = "ANNOUNCE", long = "announce", required(true))]
announce: Vec<String>,
#[structopt(name = "MD5SUM", long = "md5sum")]
@ -31,7 +31,7 @@ impl Create {
let mut announce_list = Vec::new();
for announce in &self.announce {
let tier = announce
.split(",")
.split(',')
.map(str::to_string)
.collect::<Vec<String>>();
@ -104,7 +104,7 @@ impl Create {
};
let metainfo = Metainfo {
comment: self.comment.clone(),
comment: self.comment,
encoding: consts::ENCODING_UTF8.to_string(),
announce,
announce_list,
@ -131,19 +131,19 @@ mod tests {
#[test]
fn require_input_argument() {
let env = environment(&[]);
let mut env = environment(&[]);
assert!(matches!(env.run(), Err(Error::Clap { .. })));
}
#[test]
fn require_input_present() {
let env = environment(&["--input", "foo", "--announce", "http://bar"]);
let mut env = environment(&["--input", "foo", "--announce", "http://bar"]);
assert!(matches!(env.run(), Err(Error::Filesystem { .. })));
}
#[test]
fn torrent_file_is_bencode_dict() {
let env = environment(&["--input", "foo", "--announce", "http://bar"]);
let mut env = environment(&["--input", "foo", "--announce", "http://bar"]);
fs::write(env.resolve("foo"), "").unwrap();
env.run().unwrap();
let torrent = env.resolve("foo.torrent");
@ -154,7 +154,7 @@ mod tests {
#[test]
fn privacy_defaults_to_false() {
let env = environment(&["--input", "foo", "--announce", "http://bar"]);
let mut env = environment(&["--input", "foo", "--announce", "http://bar"]);
fs::write(env.resolve("foo"), "").unwrap();
env.run().unwrap();
let torrent = env.resolve("foo.torrent");
@ -165,7 +165,7 @@ mod tests {
#[test]
fn privacy_flag_sets_privacy() {
let env = environment(&["--input", "foo", "--announce", "http://bar", "--private"]);
let mut env = environment(&["--input", "foo", "--announce", "http://bar", "--private"]);
fs::write(env.resolve("foo"), "").unwrap();
env.run().unwrap();
let torrent = env.resolve("foo.torrent");
@ -176,14 +176,14 @@ mod tests {
#[test]
fn tracker_flag_must_be_url() {
let env = environment(&["--input", "foo", "--announce", "bar"]);
let mut env = environment(&["--input", "foo", "--announce", "bar"]);
fs::write(env.resolve("foo"), "").unwrap();
assert!(matches!(env.run(), Err(Error::AnnounceUrlParse { .. })));
}
#[test]
fn announce_single() {
let env = environment(&["--input", "foo", "--announce", "http://bar"]);
let mut env = environment(&["--input", "foo", "--announce", "http://bar"]);
fs::write(env.resolve("foo"), "").unwrap();
env.run().unwrap();
let torrent = env.resolve("foo.torrent");
@ -195,7 +195,7 @@ mod tests {
#[test]
fn announce_single_tier() {
let env = environment(&["--input", "foo", "--announce", "http://bar,http://baz"]);
let mut env = environment(&["--input", "foo", "--announce", "http://bar,http://baz"]);
fs::write(env.resolve("foo"), "").unwrap();
env.run().unwrap();
let torrent = env.resolve("foo.torrent");
@ -210,7 +210,7 @@ mod tests {
#[test]
fn announce_multiple_tiers() {
let env = environment(&[
let mut env = environment(&[
"--input",
"foo",
"--announce",
@ -235,7 +235,7 @@ mod tests {
#[test]
fn comment_default() {
let env = environment(&["--input", "foo", "--announce", "http://bar"]);
let mut env = environment(&["--input", "foo", "--announce", "http://bar"]);
fs::write(env.resolve("foo"), "").unwrap();
env.run().unwrap();
let torrent = env.resolve("foo.torrent");
@ -246,7 +246,7 @@ mod tests {
#[test]
fn comment_set() {
let env = environment(&[
let mut env = environment(&[
"--input",
"foo",
"--announce",
@ -264,18 +264,18 @@ mod tests {
#[test]
fn piece_length_default() {
let env = environment(&["--input", "foo", "--announce", "http://bar"]);
let mut env = environment(&["--input", "foo", "--announce", "http://bar"]);
fs::write(env.resolve("foo"), "").unwrap();
env.run().unwrap();
let torrent = env.resolve("foo.torrent");
let bytes = fs::read(torrent).unwrap();
let metainfo = serde_bencode::de::from_bytes::<Metainfo>(&bytes).unwrap();
assert_eq!(metainfo.info.piece_length, 512 * 2u64.pow(10));
assert_eq!(metainfo.info.piece_length, 512 * 2u32.pow(10));
}
#[test]
fn piece_length_override() {
let env = environment(&[
let mut env = environment(&[
"--input",
"foo",
"--announce",
@ -293,7 +293,7 @@ mod tests {
#[test]
fn name() {
let env = environment(&[
let mut env = environment(&[
"--input",
"foo",
"--announce",
@ -311,7 +311,7 @@ mod tests {
#[test]
fn name_subdir() {
let env = environment(&[
let mut env = environment(&[
"--input",
"foo/bar",
"--announce",
@ -331,7 +331,7 @@ mod tests {
#[test]
fn destination_override() {
let env = environment(&[
let mut env = environment(&[
"--input",
"foo",
"--output",
@ -348,7 +348,7 @@ mod tests {
#[test]
fn created_by_default() {
let env = environment(&["--input", "foo", "--announce", "http://bar"]);
let mut env = environment(&["--input", "foo", "--announce", "http://bar"]);
fs::write(env.resolve("foo"), "").unwrap();
env.run().unwrap();
let torrent = env.resolve("foo.torrent");
@ -359,7 +359,7 @@ mod tests {
#[test]
fn created_by_unset() {
let env = environment(&[
let mut env = environment(&[
"--input",
"foo",
"--announce",
@ -376,7 +376,7 @@ mod tests {
#[test]
fn encoding() {
let env = environment(&["--input", "foo", "--announce", "http://bar"]);
let mut env = environment(&["--input", "foo", "--announce", "http://bar"]);
fs::write(env.resolve("foo"), "").unwrap();
env.run().unwrap();
let torrent = env.resolve("foo.torrent");
@ -387,7 +387,7 @@ mod tests {
#[test]
fn created_date_default() {
let env = environment(&["--input", "foo", "--announce", "http://bar"]);
let mut env = environment(&["--input", "foo", "--announce", "http://bar"]);
fs::write(env.resolve("foo"), "").unwrap();
let now = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
@ -403,7 +403,7 @@ mod tests {
#[test]
fn created_date_unset() {
let env = environment(&[
let mut env = environment(&[
"--input",
"foo",
"--announce",
@ -420,7 +420,7 @@ mod tests {
#[test]
fn single_small() {
let env = environment(&["--input", "foo", "--announce", "http://bar"]);
let mut env = environment(&["--input", "foo", "--announce", "http://bar"]);
let contents = "bar";
fs::write(env.resolve("foo"), contents).unwrap();
env.run().unwrap();
@ -439,7 +439,7 @@ mod tests {
#[test]
fn single_one_byte_piece() {
let env = environment(&[
let mut env = environment(&[
"--input",
"foo",
"--announce",
@ -474,7 +474,7 @@ mod tests {
#[test]
fn single_empty() {
let env = environment(&["--input", "foo", "--announce", "http://bar"]);
let mut env = environment(&["--input", "foo", "--announce", "http://bar"]);
let contents = "";
fs::write(env.resolve("foo"), contents).unwrap();
env.run().unwrap();
@ -493,7 +493,7 @@ mod tests {
#[test]
fn multiple_no_files() {
let env = environment(&["--input", "foo", "--announce", "http://bar"]);
let mut env = environment(&["--input", "foo", "--announce", "http://bar"]);
let dir = env.resolve("foo");
fs::create_dir(&dir).unwrap();
env.run().unwrap();
@ -506,7 +506,7 @@ mod tests {
#[test]
fn multiple_one_file() {
let env = environment(&["--input", "foo", "--announce", "http://bar"]);
let mut env = environment(&["--input", "foo", "--announce", "http://bar"]);
let dir = env.resolve("foo");
fs::create_dir(&dir).unwrap();
let file = dir.join("bar");
@ -522,7 +522,7 @@ mod tests {
#[test]
fn multiple_three_files() {
let env = environment(&["--input", "foo", "--announce", "http://bar"]);
let mut env = environment(&["--input", "foo", "--announce", "http://bar"]);
let dir = env.resolve("foo");
fs::create_dir(&dir).unwrap();
fs::write(dir.join("a"), "abc").unwrap();

View File

@ -11,7 +11,7 @@ pub(crate) struct Stats {
}
impl Stats {
pub(crate) fn run(self, env: &Environment, unstable: bool) -> Result<(), Error> {
pub(crate) fn run(self, env: &mut Environment, unstable: bool) -> Result<(), Error> {
if !unstable {
return Err(Error::Unstable {
feature: "torrent stats subcommand",
@ -23,7 +23,7 @@ impl Stats {
let mut extractor = Extractor::new(&self.extract_patterns);
for result in WalkDir::new(path).sort_by(|a, b| a.file_name().cmp(b.file_name())) {
if extractor.torrents >= self.limit.unwrap_or(u64::MAX) {
if extractor.torrents >= self.limit.unwrap_or(u64::max_value()) {
break;
}
@ -32,25 +32,29 @@ impl Stats {
extractor.process(entry.path());
}
println!("Torrents processed: {}", extractor.torrents);
println!("Read failed: {}", extractor.io_errors);
println!("Decode failed: {}", extractor.bencode_decode_errors);
errln!(env, "Torrents processed: {}", extractor.torrents);
errln!(env, "Read failed: {}", extractor.io_errors);
errln!(
env,
"Decode failed: {}",
extractor.bencode_decode_errors
);
let mut paths = extractor.paths.into_iter().collect::<Vec<(String, u64)>>();
paths.sort_by_key(|(_, count)| Reverse(*count));
let max = paths.iter().map(|(_, count)| *count).max().unwrap_or(0);
let width = max.to_string().len();
println!("Keys:");
errln!(env, "Keys:");
for (key, count) in &paths {
if key.starts_with("info/files") {
continue;
}
println!("{:<width$} - {}", count, key, width = width);
errln!(env, "{:<width$} - {}", count, key, width = width);
}
for (key, count) in paths {
if key.starts_with("info/files") {
println!("{:<width$} - {}", count, key, width = width);
errln!(env, "{:<width$} - {}", count, key, width = width);
}
}
@ -60,15 +64,16 @@ impl Stats {
.into_iter()
.collect::<Vec<(String, Vec<String>)>>();
println!("Values:");
errln!(env, "Values:");
for (pattern, values) in values {
println!("{}: ", pattern);
err!(env, "{}: ", pattern);
for (i, value) in values.iter().enumerate() {
if i > 0 {
print!(", ");
err!(env, ", ");
}
print!("{}", value);
err!(env, "{}", value);
}
errln!(env)
}
}
@ -87,10 +92,11 @@ struct Extractor {
}
impl Extractor {
fn new(regexes: &[Regex]) -> Extractor {
let regex_set = RegexSet::new(regexes.iter().map(Regex::as_str)).unwrap();
fn new(regexes: &[Regex]) -> Self {
let regex_set = RegexSet::new(regexes.iter().map(Regex::as_str))
.expect("Validated regex pattern failed to recompile in regex set");
Extractor {
Self {
bencode_decode_errors: 0,
io_errors: 0,
paths: HashMap::new(),
@ -112,20 +118,18 @@ impl Extractor {
self.torrents += 1;
let contents = match fs::read(&path) {
Ok(contents) => contents,
Err(_) => {
let contents = if let Ok(contents) = fs::read(&path) {
contents
} else {
self.io_errors += 1;
return;
}
};
let value = match bencode::Value::decode(&contents) {
Ok(value) => value,
Err(_) => {
let value = if let Ok(value) = bencode::Value::decode(&contents) {
value
} else {
self.bencode_decode_errors += 1;
return;
}
};
self.extract(&value);