clippy config & fixes; enable LTO

This commit is contained in:
Luke Street 2022-02-03 02:36:41 -05:00
parent 46fa0c59ff
commit 6b8d41b130
9 changed files with 38 additions and 26 deletions

View File

@ -13,13 +13,19 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.toolchain }}
override: true
components: rustfmt, clippy
- uses: EmbarkStudios/cargo-deny-action@v1
- uses: actions-rs/cargo@v1
with:
command: check
args: --all-features
- uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-features
build:
name: Build
@ -33,12 +39,13 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.toolchain }}
override: true
- uses: actions-rs/cargo@v1
with:
command: test
args: --all-features
args: --release --all-features
- uses: actions-rs/cargo@v1
with:
command: build

View File

@ -12,11 +12,15 @@ Rust library and CLI tool for reading GameCube and Wii disc images.
"""
keywords = ["gamecube", "wii", "iso", "nfs", "gcm"]
categories = ["command-line-utilities", "parser-implementations"]
rust-version = "1.51"
[[bin]]
name = "nodtool"
path = "src/bin.rs"
[profile.release]
lto = true
[dependencies]
aes = "0.7.5"
anyhow = "1.0.53"

1
clippy.toml Normal file
View File

@ -0,0 +1 @@
msrv = "1.51"

View File

@ -5,7 +5,6 @@ use std::{
};
use clap::{clap_app, AppSettings};
use file_size;
use nod::{
disc::{new_disc_base, PartReadStream},
fst::NodeType,

View File

@ -52,7 +52,7 @@ impl<'a> Read for GCPartReadStream<'a> {
while rem > 0 {
if block != self.cur_block as usize {
self.stream.read(&mut self.buf)?;
self.stream.read_exact(&mut self.buf)?;
self.cur_block = block as u64;
}

View File

@ -105,7 +105,7 @@ struct Ticket {
}
#[derive(Debug, PartialEq, BinRead)]
struct TMDContent {
struct TmdContent {
id: u32,
index: u16,
content_type: u16,
@ -114,7 +114,7 @@ struct TMDContent {
}
#[derive(Debug, PartialEq, BinRead)]
struct TMD {
struct Tmd {
sig_type: SigType,
#[br(count = 256)]
sig: Vec<u8>,
@ -137,7 +137,7 @@ struct TMD {
#[br(pad_after = 2)]
boot_idx: u16,
#[br(count = num_contents)]
contents: Vec<TMDContent>,
contents: Vec<TmdContent>,
}
#[derive(Debug, PartialEq, BinRead)]
@ -176,7 +176,7 @@ struct WiiPartitionHeader {
data_size: u64,
#[br(seek_before = SeekFrom::Start(tmd_off))]
tmd: TMD,
tmd: Tmd,
#[br(seek_before = SeekFrom::Start(cert_chain_off))]
ca_cert: Certificate,
tmd_cert: Certificate,
@ -226,7 +226,7 @@ impl DiscBase for DiscWii {
.parts
.iter()
.find(|v| v.part_type == WiiPartType::Data)
.ok_or(Error::DiscFormat("Failed to locate data partition".to_string()))?;
.ok_or_else(|| Error::DiscFormat("Failed to locate data partition".to_string()))?;
let data_off = part.part_header.data_off;
let has_crypto = disc_io.has_wii_crypto();
let result = Box::new(WiiPartReadStream {
@ -276,7 +276,7 @@ impl<'a> PartReadStream for WiiPartReadStream<'a> {
fn as_digest(slice: &[u8; 20]) -> digest::Output<Sha1> { (*slice).into() }
fn decrypt_block(part: &mut WiiPartReadStream, cluster: usize) -> io::Result<()> {
part.stream.read(&mut part.buf)?;
part.stream.read_exact(&mut part.buf)?;
if part.crypto.is_some() {
// Fetch IV before decrypting header
let iv = Block::from(*array_ref![part.buf, 0x3d0, 16]);

View File

@ -37,18 +37,18 @@ pub trait DiscIO: Send + Sync {
/// ```
pub fn new_disc_io(filename: &Path) -> Result<Box<dyn DiscIO>> {
let path_result = fs::canonicalize(filename);
if path_result.is_err() {
if let Err(err) = path_result {
return Result::Err(Error::Io(
format!("Failed to open {}", filename.to_string_lossy()),
path_result.unwrap_err(),
err,
));
}
let path = path_result.as_ref().unwrap();
let meta = fs::metadata(path);
if meta.is_err() {
if let Err(err) = meta {
return Result::Err(Error::Io(
format!("Failed to open {}", filename.to_string_lossy()),
meta.unwrap_err(),
err,
));
}
if !meta.unwrap().is_file() {

View File

@ -34,16 +34,16 @@ pub(crate) struct NFSHeader {
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) struct FBO {
pub(crate) struct Fbo {
pub(crate) file: u32,
pub(crate) block: u32,
pub(crate) l_block: u32,
pub(crate) offset: u32,
}
impl Default for FBO {
impl Default for Fbo {
fn default() -> Self {
FBO { file: u32::MAX, block: u32::MAX, l_block: u32::MAX, offset: u32::MAX }
Fbo { file: u32::MAX, block: u32::MAX, l_block: u32::MAX, offset: u32::MAX }
}
}
@ -57,7 +57,7 @@ impl NFSHeader {
(((total_block_count as u64) * 0x8000u64 + (0x200u64 + 0xF9FFFFFu64)) / 0xFA00000u64) as u32
}
pub(crate) fn logical_to_fbo(&self, offset: u64) -> FBO {
pub(crate) fn logical_to_fbo(&self, offset: u64) -> Fbo {
let block_div = (offset / 0x8000) as u32;
let block_off = (offset % 0x8000) as u32;
let mut block = u32::MAX;
@ -70,9 +70,9 @@ impl NFSHeader {
physical_block += range.num_blocks;
}
if block == u32::MAX {
FBO::default()
Fbo::default()
} else {
FBO { file: block / 8000, block: block % 8000, l_block: block_div, offset: block_off }
Fbo { file: block / 8000, block: block % 8000, l_block: block_div, offset: block_off }
}
}
}
@ -97,7 +97,7 @@ pub(crate) struct NFSReadStream<'a> {
file: Option<File>,
crypto: Aes128,
// Physical address - all UINT32_MAX indicates logical zero block
phys_addr: FBO,
phys_addr: Fbo,
// Logical address
offset: u64,
// Active file stream and its offset as set in the system.
@ -127,7 +127,7 @@ impl<'a> NFSReadStream<'a> {
io::Result::Ok(())
}
fn set_phys_addr(&mut self, phys_addr: FBO) -> Result<()> {
fn set_phys_addr(&mut self, phys_addr: Fbo) -> Result<()> {
// If we're just changing the offset, nothing else needs to be done
if self.phys_addr.file == phys_addr.file && self.phys_addr.block == phys_addr.block {
self.phys_addr.offset = phys_addr.offset;
@ -151,12 +151,12 @@ impl<'a> NFSReadStream<'a> {
// Read block, handling 0x200 overlap case
if phys_addr.block == 7999 {
self.file.as_ref().unwrap().read(&mut self.buf[..BUFFER_SIZE - 0x200])?;
self.file.as_ref().unwrap().read_exact(&mut self.buf[..BUFFER_SIZE - 0x200])?;
self.set_cur_file(self.cur_file + 1)?;
self.file.as_ref().unwrap().read(&mut self.buf[BUFFER_SIZE - 0x200..])?;
self.file.as_ref().unwrap().read_exact(&mut self.buf[BUFFER_SIZE - 0x200..])?;
self.cur_block = 0;
} else {
self.file.as_ref().unwrap().read(&mut self.buf)?;
self.file.as_ref().unwrap().read_exact(&mut self.buf)?;
self.cur_block += 1;
}
@ -191,7 +191,7 @@ impl<'a> Read for NFSReadStream<'a> {
read_size = BUFFER_SIZE - block_offset
}
buf[read..read + read_size]
.copy_from_slice(&mut self.buf[block_offset..block_offset + read_size]);
.copy_from_slice(&self.buf[block_offset..block_offset + read_size]);
read += read_size;
rem -= read_size;
self.offset += read_size as u64;
@ -233,7 +233,7 @@ impl DiscIO for DiscIONFS {
disc_io: self,
file: Option::None,
crypto: Aes128::new(&self.key.into()),
phys_addr: FBO::default(),
phys_addr: Fbo::default(),
offset,
cur_file: u32::MAX,
cur_block: u32::MAX,

View File

@ -191,6 +191,7 @@ impl Read for ByteReadStream<'_> {
let total = self.bytes.len();
let pos = self.position as usize;
if len + pos > total {
#[allow(clippy::comparison_chain)]
if pos > total {
return Err(io::Error::from(io::ErrorKind::UnexpectedEof));
} else if pos == total {