Skip to content

Commit

Permalink
Strict clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
harmless-tech committed Feb 26, 2024
1 parent 7f32087 commit d50e287
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 }"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
30 changes: 17 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -60,36 +63,37 @@ fn main() -> anyhow::Result<()> {
input: pargs.free_from_os_str(|s| Ok::<PathBuf, String>(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);

let mut file: Box<dyn Read> =
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<dyn Read>, output: PathBuf) -> anyhow::Result<()> {
fn unzip(read: &mut Box<dyn Read>, 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() {
Expand All @@ -105,7 +109,7 @@ fn unzip(read: &mut Box<dyn Read>, 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}"),
}
}

Expand Down

0 comments on commit d50e287

Please sign in to comment.