diff --git a/Cargo.toml b/Cargo.toml index ad878b0..0b1bd2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ description = "A basic tar/zip extraction program" readme = "README.md" license = "MIT" repository = "https://github.com/cargo-prebuilt/qstract" +categories = ["command-line-utilities"] keywords = ["command-line-tool", "extract", "tar", "zip"] rust-version = "1.74" include = [ @@ -44,6 +45,17 @@ opt-level = 0 lto = false codegen-units = 16 +[lints.clippy] +cargo = "deny" +correctness = "deny" +complexity = "deny" +enum_glob_use = "deny" +nursery = "deny" +pedantic = "deny" +perf = "deny" +style = "deny" +suspicious = "deny" + [package.metadata.binstall] pkg-url = "{ repo }/releases/download/v{ version }/{ target }.tar.gz" bin-dir = "{ bin }{ binary-ext }" diff --git a/README.md b/README.md index e3352db..c94efea 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ A basic tar/zip extraction program. - `-C` for directory to extract to. - `-z` for gzip. -- `--zip` for zip. (Only deflate and deflate64) +- `--zip` for zip. (none, deflate, deflate64) First positional arg is the file to extract. diff --git a/deny.toml b/deny.toml index bc65cf7..ed09089 100644 --- a/deny.toml +++ b/deny.toml @@ -144,7 +144,7 @@ registries = [ # https://embarkstudios.github.io/cargo-deny/checks/bans/cfg.html [bans] # Lint level for when multiple versions of the same crate are detected -multiple-versions = "warn" +multiple-versions = "allow" # Lint level for when a crate version requirement is `*` wildcards = "allow" # The graph highlighting used when creating dotgraphs for crates diff --git a/justfile b/justfile index d3e9df5..31057d1 100644 --- a/justfile +++ b/justfile @@ -16,6 +16,7 @@ check: cargo +nightly fmt --check cargo clippy --all-targets --locked --workspace -- -D warnings cargo clippy --all-targets --locked --workspace --release -- -D warnings + cargo deny check docker: docker run -it --rm --pull=always \ diff --git a/src/main.rs b/src/main.rs index bc5b8ce..e279b7c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,12 @@ +#![forbid(unsafe_code)] +#![allow(clippy::multiple_crate_versions)] + use flate2::bufread::GzDecoder; use rc_zip_sync::{rc_zip::parse::EntryKind, ReadZip}; use std::{ fs::File, io::{BufReader, Read}, - path::PathBuf, + path::{Path, PathBuf}, }; use tar::Archive; @@ -60,9 +63,10 @@ fn main() -> anyhow::Result<()> { input: pargs.free_from_os_str(|s| Ok::(PathBuf::from(s)))?, }; - if args.gzip && args.zip { - panic!("Cannot use gzip and zip at the same time."); - } + assert!( + !(args.gzip && args.zip), + "Cannot use gzip and zip at the same time." + ); let file = File::open(args.input)?; let file = BufReader::new(file); @@ -70,26 +74,26 @@ fn main() -> anyhow::Result<()> { let mut file: Box = if args.gzip { Box::new(GzDecoder::new(file)) } else { Box::new(file) }; - if !args.zip { - let mut archive = Archive::new(file); - archive.unpack(args.output)?; + if args.zip { + unzip(&mut file, &args.output)?; } else { - unzip(&mut file, args.output)?; + let mut archive = Archive::new(file); + archive.unpack(args.output)?; } Ok(()) } -fn unzip(read: &mut Box, output: PathBuf) -> anyhow::Result<()> { +fn unzip(read: &mut Box, output: &Path) -> anyhow::Result<()> { let mut bytes = Vec::new(); read.read_to_end(&mut bytes)?; let reader = bytes.read_zip()?; for entry in reader.entries() { - let name = match entry.sanitized_name() { - Some(name) => name, - None => continue, + let Some(name) = entry.sanitized_name() + else { + continue; }; match entry.kind() { @@ -105,7 +109,7 @@ fn unzip(read: &mut Box, output: PathBuf) -> anyhow::Result<()> { let mut r = entry.reader(); std::io::copy(&mut r, &mut w)?; } - EntryKind::Symlink => eprintln!("Unsupported symlink, skipping {}", name), + EntryKind::Symlink => eprintln!("Unsupported symlink, skipping {name}"), } }