From b2cff1edb60ff4df534424eb25c89b291963c28f Mon Sep 17 00:00:00 2001 From: JonathanHelianthicusDoe Date: Mon, 30 Dec 2019 22:09:30 -0800 Subject: [PATCH] Cleanup and formatting to make everything stable; v1.0.0 --- .gitignore | 1 + Cargo.toml | 6 +-- README.md | 27 +++++++---- build.sh | 11 ----- deny.toml | 2 +- rustfmt.toml | 18 ++++--- src/command.rs | 23 +++++---- src/config.rs | 60 +++++++++++++----------- src/error.rs | 124 +++++++++++++++++++++++++++++-------------------- src/login.rs | 27 ++++++----- src/main.rs | 7 +-- src/update.rs | 78 ++++++++++++++++++------------- src/util.rs | 12 ++--- 13 files changed, 217 insertions(+), 179 deletions(-) delete mode 100755 build.sh diff --git a/.gitignore b/.gitignore index b45c83e..9be35f8 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ Cargo.lock # Stray things *.txt +build.sh diff --git a/Cargo.toml b/Cargo.toml index 41f3d6a..01e240b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "shticker_book_unwritten" -version = "0.6.1" +version = "1.0.0" authors = ["Dr. Jonathan Helianthicus Doe, IV "] edition = "2018" description = "Minimal CLI launcher for the Toontown Rewritten MMORPG" @@ -14,7 +14,7 @@ license = "GPL-3.0-or-later" [dependencies] bzip2 = "0.3.3" rpassword = "4.0.3" -serde = { version = "1.0.103", features = ["derive"] } +serde = { version = "1.0.104", features = ["derive"] } serde_json = "1.0.44" sha-1 = "0.8.1" @@ -24,7 +24,7 @@ default-features = false features = ["suggestions", "vec_map"] [dependencies.reqwest] -version = "0.10.0-alpha.2" +version = "0.10.0" features = ["blocking", "default-tls"] [profile.release] diff --git a/README.md b/README.md index 0143771..e19b350 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![crates.io](https://img.shields.io/crates/v/shticker_book_unwritten)](https://crates.io/crates/shticker_book_unwritten) [![GPL v3+](https://img.shields.io/badge/license-GNU%20GPL%20v3%2B-bd0000)](./LICENSE) [![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/) +[![minimum supported rust version 1.39.0](https://img.shields.io/badge/rustc-%3E%3D1.39.0-dea584)](https://rustup.rs/) [![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/JonathanHelianthicusDoe/shticker_book_unwritten)](https://github.com/JonathanHelianthicusDoe/shticker_book_unwritten) ![shticker\_book\_unwritten logo](./img/shticker_book_unwritten_256x256.png) @@ -16,6 +17,9 @@ Currently builds and functions on GNU/Linux, Windows NT (using the MSVC toolchain), and macOS (be sure to allow Terminal the ability to monitor inputs). +**Mirror:** + + ## Installing ### From pre-compiled binary @@ -25,7 +29,8 @@ You can get pre-compiled binaries from [the releases page][releases] on GitHub. ### From [crates.io](https://crates.io/) Requires a distribution of [Rust](https://www.rust-lang.org/)/cargo, which you -can get from [rustup](https://rustup.rs/). +can get from [rustup](https://rustup.rs/). The minimum supported version of +rustc is 1.39.0. ```bash cargo install shticker_book_unwritten @@ -41,7 +46,8 @@ cargo install -f shticker_book_unwritten ### From GitHub git repository Requires a distribution of [Rust](https://www.rust-lang.org/)/cargo, which you -can get from [rustup](https://rustup.rs/). +can get from [rustup](https://rustup.rs/). The minimum supported version of +rustc is 1.39.0. ```bash git clone https://github.com/JonathanHelianthicusDoe/shticker_book_unwritten.git @@ -80,12 +86,17 @@ upstream. This entire work (including this document & all associated source code) is licensed to anyone under the terms of the [GNU General Public License, version -3](https://www.gnu.org/licenses/gpl-3.0.html) (or any higher version, at your -option). For the relevant legal text, see the [LICENSE](./LICENSE) file. +3](https://www.gnu.org/licenses/gpl-3.0.html) (or any later version of the same +license, at the licensee’s option). For the relevant legal text, see the +[LICENSE](./LICENSE) file. [![GNU GPL v3+](https://www.gnu.org/graphics/gplv3-or-later.png "GNU GPL v3+")](https://www.gnu.org/licenses/gpl-3.0.html) +Versions of shticker\_book\_unwritten prior to 1.0.0 were licensed under the +terms of the [GNU Affero General Public License, version +3](https://www.gnu.org/licenses/agpl-3.0.html) or later. + This work contains ([Rust](https://www.rust-lang.org/)-ified) code from [bsdiff 4.3](http://www.daemonology.net/bsdiff/), which is licensed under a slightly modified version of [the FreeBSD @@ -94,10 +105,10 @@ relevant legal text, see the [LICENSE.bsdiff4](./LICENSE.bsdiff4) file. The shticker\_book\_unwritten logo is licensed to anyone under the terms of the [Creative Commons Attribution-ShareAlike license, version -4.0](https://creativecommons.org/licenses/by-sa/4.0/) (or any higher version, -at your option). For the relevant legal text, see -[https://creativecommons.org/licenses/by-sa/4.0/legalcode][cc-by-sa], or the -[img/LICENSE.imgs](img/LICENSE.imgs) file for a plaintext version. +4.0](https://creativecommons.org/licenses/by-sa/4.0/) (or any later version of +the same license, at the licensee’s option). For the relevant legal text, +see [https://creativecommons.org/licenses/by-sa/4.0/legalcode][cc-by-sa], or +the [img/LICENSE.imgs](img/LICENSE.imgs) file for a plaintext version. [![CC BY-SA 4.0+](https://i.creativecommons.org/l/by-sa/4.0/88x31.png "CC BY-SA 4.0+")](https://creativecommons.org/licenses/by-sa/4.0/) diff --git a/build.sh b/build.sh deleted file mode 100755 index 9f5dbd9..0000000 --- a/build.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -cargo update --aggressive -if [[ "$1" =~ ^-?d(ebug)?$ ]]; then - cargo build -else - cargo rustc --release -- -C target-cpu=native - strip ./target/release/shticker_book_unwritten -fi diff --git a/deny.toml b/deny.toml index adc9cdd..67a4182 100644 --- a/deny.toml +++ b/deny.toml @@ -11,7 +11,7 @@ deny = [ "AFL-2.0", "AFL-2.1", "AFL-3.0", - "AGPL-1.0-only", + "AGPL-1.0", "Apache-1.0", "Apache-1.1", "APSL-1.0", diff --git a/rustfmt.toml b/rustfmt.toml index 5971bbe..f950886 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,16 +1,14 @@ -format_strings = true -imports_indent = "Block" -imports_layout = "HorizontalVertical" -match_arm_blocks = false -match_block_trailing_comma = true +edition = "2018" +fn_args_layout = "Tall" +force_explicit_abi = true +hard_tabs = false max_width = 79 -merge_imports = true +merge_derives = true newline_style = "Unix" -normalize_comments = false remove_nested_parens = true -reorder_impl_items = true -struct_field_align_threshold = 24 +reorder_imports = true +reorder_modules = true tab_spaces = 4 use_field_init_shorthand = true +use_small_heuristics = "Default" use_try_shorthand = true -wrap_comments = false diff --git a/src/command.rs b/src/command.rs index f7c9f11..94a649c 100644 --- a/src/command.rs +++ b/src/command.rs @@ -5,8 +5,7 @@ use std::{ io::{self, prelude::*}, num::NonZeroUsize, path::Path, - process, - time, + process, time, }; const HELP_TEXT: &str = "\ @@ -95,11 +94,11 @@ pub fn enter_command_mode<'a, P: AsRef, U: Iterator>( Some("help") | Some("?") => { help(); check_children(quiet, &mut children)?; - }, + } Some("about") => { about(); check_children(quiet, &mut children)?; - }, + } Some("quit") | Some("exit") => { check_children(quiet, &mut children)?; if children.is_empty() { @@ -137,7 +136,7 @@ pub fn enter_command_mode<'a, P: AsRef, U: Iterator>( .read_line(&mut command_buf) .map_err(Error::StdinError)?; } - }, + } Some("update") | Some("up") => { check_children(quiet, &mut children)?; @@ -149,7 +148,7 @@ pub fn enter_command_mode<'a, P: AsRef, U: Iterator>( println!("Unexpected argument: {}", arg); continue 'outer; - }, + } } } @@ -173,7 +172,7 @@ pub fn enter_command_mode<'a, P: AsRef, U: Iterator>( ); } } - }, + } Some("login") | Some("play") | Some("launch") => { login::login( config, @@ -184,26 +183,26 @@ pub fn enter_command_mode<'a, P: AsRef, U: Iterator>( &mut children, )?; check_children(quiet, &mut children)?; - }, + } Some("instances") | Some("running") => { check_children(quiet, &mut children)?; display_instances(&children); - }, + } Some("kill") | Some("close") => { check_children(quiet, &mut children)?; kill_instance(quiet, &mut children, argv.next())?; - }, + } Some("accounts") | Some("logins") => { check_children(quiet, &mut children)?; display_accounts(config, &children)?; - }, + } _ => { check_children(quiet, &mut children)?; println!( "Unrecognized command. Type help or ? to get a list of \ commands.", ); - }, + } } } diff --git a/src/config.rs b/src/config.rs index e8c0df4..53f7eeb 100644 --- a/src/config.rs +++ b/src/config.rs @@ -16,12 +16,12 @@ const DEFAULT_CDN_URI: &str = #[derive(Deserialize, Serialize, Debug)] pub struct Config { - pub install_dir: PathBuf, - pub cache_dir: PathBuf, - pub manifest_uri: String, - pub cdn_uri: String, + pub install_dir: PathBuf, + pub cache_dir: PathBuf, + pub manifest_uri: String, + pub cdn_uri: String, pub store_passwords: bool, - pub accounts: serde_json::Map, + pub accounts: serde_json::Map, } impl Config { @@ -80,11 +80,12 @@ pub fn get_config( match key.as_str() { "XDG_CONFIG_HOME" => xdg_config_home = value, "HOME" => home = value, - _ => + _ => { if !(home.is_empty() || xdg_config_home.is_empty()) { break; - }, + } + } } } @@ -107,10 +108,11 @@ pub fn get_config( for (key, value) in env::vars() { match key.as_str() { "APPDATA" => appdata = value, - _ => + _ => { if !appdata.is_empty() { break; - }, + } + } } } @@ -129,10 +131,11 @@ pub fn get_config( for (key, value) in env::vars() { match key.as_str() { "HOME" => home = value, - _ => + _ => { if !(home.is_empty()) { break; - }, + } + } } } @@ -180,12 +183,13 @@ pub fn get_config( .map_err(Error::SerializeError)?; Ok((inject_arg_values(new_config), config_path)) - }, - io::ErrorKind::PermissionDenied => + } + io::ErrorKind::PermissionDenied => { Err(Error::PermissionDenied( format!("opening {:?}", config_path), ioe, - )), + )) + } _ => Err(Error::UnknownIoError( format!("opening {:?}", config_path), ioe, @@ -199,16 +203,16 @@ pub fn get_config( Ok(( Config { - install_dir: PathBuf::from(install_path.ok_or_else( - || Error::MissingCommandLineArg("--install-dir"), - )?), - cache_dir: PathBuf::from(cache_path.ok_or_else( - || Error::MissingCommandLineArg("--cache-dir"), - )?), - manifest_uri: DEFAULT_MANIFEST_URI.to_owned(), - cdn_uri: DEFAULT_CDN_URI.to_owned(), + install_dir: PathBuf::from(install_path.ok_or_else(|| { + Error::MissingCommandLineArg("--install-dir") + })?), + cache_dir: PathBuf::from(cache_path.ok_or_else(|| { + Error::MissingCommandLineArg("--cache-dir") + })?), + manifest_uri: DEFAULT_MANIFEST_URI.to_owned(), + cdn_uri: DEFAULT_CDN_URI.to_owned(), store_passwords: false, - accounts: serde_json::Map::default(), + accounts: serde_json::Map::default(), }, PathBuf::new(), )) @@ -250,18 +254,18 @@ fn prompt_for_config_values>( println!(); return Ok(Config { - install_dir: PathBuf::from(install_dir.trim()), - cache_dir: config_path + install_dir: PathBuf::from(install_dir.trim()), + cache_dir: config_path .as_ref() .parent() .ok_or_else(|| { Error::BadConfigPath(config_path.as_ref().to_owned()) })? .join("cache"), - manifest_uri: DEFAULT_MANIFEST_URI.to_owned(), - cdn_uri: DEFAULT_CDN_URI.to_owned(), + manifest_uri: DEFAULT_MANIFEST_URI.to_owned(), + cdn_uri: DEFAULT_CDN_URI.to_owned(), store_passwords: yes_no_trimmed == "yes", - accounts: serde_json::Map::default(), + accounts: serde_json::Map::default(), }); } diff --git a/src/error.rs b/src/error.rs index 8e1393d..0cb1446 100644 --- a/src/error.rs +++ b/src/error.rs @@ -63,38 +63,50 @@ impl fmt::Display for Error { environment variable is unset or empty"; f.write_str(MSG) - }, - Self::BadConfigPath(bcp) => - write!(f, "Bad config file path specified: {}", bcp.display()), - Self::MkdirError(path, ioe) => - write!(f, "`mkdir -p {:?}` failed:\n\t{}", path, ioe), - Self::PermissionDenied(info, ioe) => - write!(f, "Permission denied while {}:\n\t{}", info, ioe), + } + Self::BadConfigPath(bcp) => { + write!(f, "Bad config file path specified: {}", bcp.display()) + } + Self::MkdirError(path, ioe) => { + write!(f, "`mkdir -p {:?}` failed:\n\t{}", path, ioe) + } + Self::PermissionDenied(info, ioe) => { + write!(f, "Permission denied while {}:\n\t{}", info, ioe) + } Self::StdoutError(ioe) => write!(f, "stdout error:\n\t{}", ioe), Self::StdinError(ioe) => write!(f, "stdin error:\n\t{}", ioe), - Self::UnknownIoError(info, ioe) => - write!(f, "Unknown I/O error while {}:\n\t{}", info, ioe), - Self::SerializeError(se) => - write!(f, "Failed to write JSON:\n\t{}", se), - Self::DeserializeError(de) => - write!(f, "Failed to read JSON:\n\t{}", de), - Self::ManifestRequestError(mre) => - write!(f, "Error requesting manifest:\n\t{}", mre), + Self::UnknownIoError(info, ioe) => { + write!(f, "Unknown I/O error while {}:\n\t{}", info, ioe) + } + Self::SerializeError(se) => { + write!(f, "Failed to write JSON:\n\t{}", se) + } + Self::DeserializeError(de) => { + write!(f, "Failed to read JSON:\n\t{}", de) + } + Self::ManifestRequestError(mre) => { + write!(f, "Error requesting manifest:\n\t{}", mre) + } Self::ManifestRequestStatusError(sc) => write!( f, "Bad status code after requesting manifest:\n\t{}", sc, ), - Self::BadManifestFormat(s) => - write!(f, "Bad manifest format:\n\t{}", s), - Self::FileReadError(path, ioe) => - write!(f, "Failed to read from {:?}:\n\t{}", path, ioe), - Self::FileWriteError(path, ioe) => - write!(f, "Failed to write to {:?}:\n\t{}", path, ioe), - Self::DownloadRequestError(dre) => - write!(f, "Error requesting download: {}", dre), - Self::DownloadRequestStatusError(sc) => - write!(f, "Bad status code after requesting download: {}", sc), + Self::BadManifestFormat(s) => { + write!(f, "Bad manifest format:\n\t{}", s) + } + Self::FileReadError(path, ioe) => { + write!(f, "Failed to read from {:?}:\n\t{}", path, ioe) + } + Self::FileWriteError(path, ioe) => { + write!(f, "Failed to write to {:?}:\n\t{}", path, ioe) + } + Self::DownloadRequestError(dre) => { + write!(f, "Error requesting download: {}", dre) + } + Self::DownloadRequestStatusError(sc) => { + write!(f, "Bad status code after requesting download: {}", sc) + } Self::CopyIntoFileError(path, cife) => write!( f, "Failure copying HTTP-downloaded data into {:?}:\n\t{}", @@ -116,15 +128,19 @@ impl fmt::Display for Error { "Error while seeking through file {:?}:\n\t{}", path, ioe, ), - Self::PatchSanityCheckFail(i) => - write!(f, "During patching, sanity check #{} failed", i), - Self::FileRenameError(from, to) => - write!(f, "Error renaming file from {:?} to {:?}", from, to), + Self::PatchSanityCheckFail(i) => { + write!(f, "During patching, sanity check #{} failed", i) + } + Self::FileRenameError(from, to) => { + write!(f, "Error renaming file from {:?} to {:?}", from, to) + } Self::NotDir(path) => write!(f, "{:?} is not a directory", path), - Self::RemoveFileError(path, ioe) => - write!(f, "Error removing file {:?}:\n\t{}", path, ioe), - Self::MissingFile(name) => - write!(f, "Expected \"{}\" file to exist", name), + Self::RemoveFileError(path, ioe) => { + write!(f, "Error removing file {:?}:\n\t{}", path, ioe) + } + Self::MissingFile(name) => { + write!(f, "Expected \"{}\" file to exist", name) + } Self::PermissionsSetError(path, ioe) => write!( f, "Failure to set permissions on file {:?}:\n\t{}", @@ -135,20 +151,27 @@ impl fmt::Display for Error { "Expected the {} command line argument to be present", a, ), - Self::PasswordReadError(ioe) => - write!(f, "Error reading password:\n\t{}", ioe), - Self::HttpClientCreateError(hcce) => - write!(f, "Error creating HTTP client:\n\t{}", hcce), - Self::PostError(pe) => - write!(f, "Error sending HTTP POST:\n\t{}", pe), - Self::BadLoginResponse(blr) => - write!(f, "Bad login response:\n\t{}", blr), - Self::UnexpectedSuccessValue(value) => - write!(f, "Unexpected \"success\" value: {}", value), - Self::ThreadSpawnError(ioe) => - write!(f, "Error spawning thread:\n\t{}", ioe), - Self::ThreadJoinError(ioe) => - write!(f, "Error attempting to join thread:\n\t{}", ioe), + Self::PasswordReadError(ioe) => { + write!(f, "Error reading password:\n\t{}", ioe) + } + Self::HttpClientCreateError(hcce) => { + write!(f, "Error creating HTTP client:\n\t{}", hcce) + } + Self::PostError(pe) => { + write!(f, "Error sending HTTP POST:\n\t{}", pe) + } + Self::BadLoginResponse(blr) => { + write!(f, "Bad login response:\n\t{}", blr) + } + Self::UnexpectedSuccessValue(value) => { + write!(f, "Unexpected \"success\" value: {}", value) + } + Self::ThreadSpawnError(ioe) => { + write!(f, "Error spawning thread:\n\t{}", ioe) + } + Self::ThreadJoinError(ioe) => { + write!(f, "Error attempting to join thread:\n\t{}", ioe) + } Self::ProcessKillError(pid, ioe) => write!( f, "Error killing child process with pid {}:\n\t{}", @@ -166,9 +189,10 @@ impl fmt::Display for Error { } Ok(()) - }, - Self::InvalidArgValue(param) => - write!(f, "Invalid value for the argument of {}", param), + } + Self::InvalidArgValue(param) => { + write!(f, "Invalid value for the argument of {}", param) + } } } } diff --git a/src/login.rs b/src/login.rs index fb5e9b9..94b222b 100644 --- a/src/login.rs +++ b/src/login.rs @@ -10,8 +10,7 @@ use std::{ ffi::OsStr, io::{self, Write}, path::Path, - process, - thread, + process, thread, time::{Duration, Instant}, }; @@ -198,12 +197,13 @@ fn handle_login_negotiation( .get("success") .and_then(|val| match val { serde_json::Value::String(s) => Some(s.as_str()), - serde_json::Value::Bool(b) => + serde_json::Value::Bool(b) => { if *b { Some("true") } else { Some("false") - }, + } + } _ => None, }) .ok_or(Error::BadLoginResponse( @@ -217,16 +217,18 @@ fn handle_login_negotiation( } return Ok(Some(response_json)); - }, - "delayed" => - response_json = enqueue(client, quiet, &response_json)?, - "partial" => + } + "delayed" => { + response_json = enqueue(client, quiet, &response_json)? + } + "partial" => { response_json = if let Some(rj) = do_2fa(client, &response_json)? { rj } else { return Ok(None); - }, + } + } "false" => { println!( "Login failed: {}", @@ -245,9 +247,10 @@ fn handle_login_negotiation( ); return Ok(None); - }, - _ => - return Err(Error::UnexpectedSuccessValue(success.to_owned())), + } + _ => { + return Err(Error::UnexpectedSuccessValue(success.to_owned())) + } } } } diff --git a/src/main.rs b/src/main.rs index 874bc91..fe3390e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,12 +11,7 @@ mod update; mod util; use clap::{ - crate_authors, - crate_description, - crate_name, - crate_version, - App, - Arg, + crate_authors, crate_description, crate_name, crate_version, App, Arg, }; use error::Error; use reqwest::blocking as rb; diff --git a/src/update.rs b/src/update.rs index ddfcbe3..2b7ea06 100644 --- a/src/update.rs +++ b/src/update.rs @@ -34,10 +34,11 @@ pub fn update( let manifest_map = match get_manifest(config, client, quiet, max_tries)? { serde_json::Value::Object(m) => m, - _ => + _ => { return Err(Error::BadManifestFormat( "Top-level value is not an Object".to_owned(), - )), + )) + } }; if !quiet { @@ -67,25 +68,28 @@ pub fn update( Error::BadManifestFormat("Missing the \"only\" key".to_owned()) })? { serde_json::Value::Array(v) => v, - _ => + _ => { return Err(Error::BadManifestFormat( "Expected \"only\"'s value to be an Array".to_owned(), - )), + )) + } }; let mut supported_by_this_arch = false; for arch_val in supported_archs { match arch_val { - serde_json::Value::String(s) => + serde_json::Value::String(s) => { if OS_AND_ARCH == s { supported_by_this_arch = true; break; - }, - _ => + } + } + _ => { return Err(Error::BadManifestFormat( "Expected OS & architecture values to be Strings" .to_owned(), - )), + )) + } } } @@ -149,8 +153,9 @@ pub fn update( ) }) .and_then(|val| match val { - serde_json::Value::String(s) => - sha_from_hash_str(s), + serde_json::Value::String(s) => { + sha_from_hash_str(s) + } _ => Err(Error::BadManifestFormat( "Expected \"compHash\" to be a String" .to_owned(), @@ -164,8 +169,9 @@ pub fn update( ) }) .and_then(|val| match val { - serde_json::Value::String(s) => - sha_from_hash_str(s), + serde_json::Value::String(s) => { + sha_from_hash_str(s) + } _ => Err(Error::BadManifestFormat( "Expected \"hash\" to be a String".to_owned(), )), @@ -185,17 +191,19 @@ pub fn update( )?; None - }, - io::ErrorKind::PermissionDenied => + } + io::ErrorKind::PermissionDenied => { return Err(Error::PermissionDenied( format!("opening {:?}", install_dir), ioe, - )), - _ => + )) + } + _ => { return Err(Error::UnknownIoError( format!("opening {:?}", install_dir), ioe, - )), + )) + } }, }; if let Some(f) = already_existing_file { @@ -293,14 +301,16 @@ fn update_existing_file, P: AsRef>( let manifest_sha = sha_from_hash_str(match file_map.get("hash") { Some(serde_json::Value::String(s)) => s, - Some(_) => + Some(_) => { return Err(Error::BadManifestFormat( "Value of \"hash\" was not a String".to_owned(), - )), - _ => + )) + } + _ => { return Err(Error::BadManifestFormat( "\"hash\" key missing".to_owned(), - )), + )) + } })?; if initial_sha == manifest_sha { @@ -345,10 +355,11 @@ fn update_existing_file, P: AsRef>( let patch_map = match patch_obj { serde_json::Value::Object(m) => m, - _ => + _ => { return Err(Error::BadManifestFormat( "Expected \"patches\" to be objects".to_owned(), - )), + )) + } }; let patch_file_name = patch_map @@ -524,7 +535,7 @@ fn get_manifest( handle_retry(e); continue; - }, + } }; if !manifest_resp.status().is_success() { handle_retry(Error::ManifestRequestStatusError( @@ -541,7 +552,7 @@ fn get_manifest( handle_retry(e); continue; - }, + } }; match serde_json::from_str(&manifest_text) @@ -598,11 +609,12 @@ fn sha_from_hash_str>(hash_str: S) -> Result<[u8; 20], Error> { b'd' | b'D' => 0x0d, b'e' | b'E' => 0x0e, b'f' | b'F' => 0x0f, - _ => + _ => { return Err(Error::BadManifestFormat(format!( "Unexpected character in SHA1 hash string: {:?}", b as char, - ))), + ))) + } }; manifest_sha[i / 2] |= nibble_val << if i % 2 == 0 { 4 } else { 0 }; @@ -689,7 +701,7 @@ fn download_file, T: AsRef>( handle_retry(e); continue; - }, + } }; if !dl_resp.status().is_success() { handle_retry(Error::DownloadRequestStatusError(dl_resp.status())); @@ -822,17 +834,19 @@ fn decompress_file>( fn ensure_dir>(path: P) -> Result<(), Error> { match fs::metadata(&path) { - Ok(md) => + Ok(md) => { if md.is_dir() { Ok(()) } else { Err(Error::NotDir(path.as_ref().to_path_buf())) - }, + } + } Err(ioe) => match ioe.kind() { - io::ErrorKind::NotFound => + io::ErrorKind::NotFound => { fs::create_dir_all(&path).map_err(|ioe| { Error::MkdirError(path.as_ref().to_path_buf(), ioe) - }), + }) + } io::ErrorKind::PermissionDenied => Err(Error::PermissionDenied( format!("obtaining metadata for {:?}", path.as_ref()), ioe, diff --git a/src/util.rs b/src/util.rs index ff923ca..b6f84ba 100644 --- a/src/util.rs +++ b/src/util.rs @@ -7,8 +7,9 @@ pub fn open_file>(path: P) -> Result { format!("opening {:?}", path.as_ref()), ioe, ), - _ => - Error::UnknownIoError(format!("opening {:?}", path.as_ref()), ioe), + _ => { + Error::UnknownIoError(format!("opening {:?}", path.as_ref()), ioe) + } }) } @@ -18,9 +19,8 @@ pub fn create_file>(path: P) -> Result { format!("creating {:?}", path.as_ref()), ioe, ), - _ => Error::UnknownIoError( - format!("creating {:?}", path.as_ref()), - ioe, - ), + _ => { + Error::UnknownIoError(format!("creating {:?}", path.as_ref()), ioe) + } }) }