From d215d9335d5a594c0bc0ced8cc4b770e11834af0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Gonz=C3=A1lez?= Date: Tue, 3 Dec 2024 21:44:59 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20Rust=202024=20edition=20update=20?= =?UTF-8?q?=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 9 +++- packages/packsquash/Cargo.toml | 10 ++-- packages/packsquash/benches/benches.rs | 6 +-- packages/packsquash/benches/pack_dataset.rs | 4 +- packages/packsquash/src/config/mod.rs | 2 +- packages/packsquash/src/lib.rs | 12 ++--- .../packsquash/src/pack_file/asset_type.rs | 4 +- .../packsquash/src/pack_file/audio_file.rs | 18 +++++-- .../pack_file/audio_file/signal_processor.rs | 4 +- .../src/pack_file/command_function_file.rs | 6 +-- .../packsquash/src/pack_file/json_file.rs | 4 +- .../src/pack_file/legacy_lang_file.rs | 6 +-- .../src/pack_file/passthrough_file.rs | 9 ++-- .../src/pack_file/png_file/image_processor.rs | 18 ++----- .../src/pack_file/shader_file/parser.rs | 4 +- packages/packsquash/src/pack_meta.rs | 10 ++-- packages/packsquash/src/squash_zip.rs | 23 ++++----- .../src/squash_zip/obfuscation_engine.rs | 16 +++--- .../pseudodir_concealment.rs | 2 +- .../src/squash_zip/relative_path.rs | 15 +++--- .../packsquash/src/squash_zip/system_id.rs | 3 +- .../packsquash/src/squash_zip/system_id/os.rs | 9 ++-- .../src/squash_zip/system_time_sanitizer.rs | 4 +- packages/packsquash/src/squash_zip/tests.rs | 46 ++++++++--------- packages/packsquash/src/vfs/os_fs.rs | 50 ++++++++----------- packages/packsquash_cli/Cargo.toml | 8 +-- .../packsquash_cli/src/bin/packsquash/main.rs | 6 +-- .../packsquash/terminal_title_setter/unix.rs | 5 +- .../terminal_title_setter/windows.rs | 2 +- 29 files changed, 147 insertions(+), 168 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index add8ccfb5..2d0bbcb72 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,13 @@ [workspace] members = ["packages/*"] -resolver = "2" +resolver = "3" + +[workspace.package] +version = "0.4.0" +repository = "https://github.com/ComunidadAylas/PackSquash" +license = "AGPL-3.0-or-later" +edition = "2024" +publish = false [patch.crates-io] # Use our fork of glsl-lang that allows it to parse #moj_import directives diff --git a/packages/packsquash/Cargo.toml b/packages/packsquash/Cargo.toml index b335b5c81..6f4b6b62c 100644 --- a/packages/packsquash/Cargo.toml +++ b/packages/packsquash/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "packsquash" description = "Minecraft resource and data pack optimizer" -version = "0.4.0" +version.workspace = true authors = ["Alejandro \"AlexTMjugador\" González"] -repository = "https://github.com/ComunidadAylas/PackSquash" -license = "AGPL-3.0-or-later" +repository.workspace = true +license.workspace = true readme = "README.md" -publish = false -edition = "2021" +publish.workspace = true +edition.workspace = true [dependencies] bytes = "1.9.0" diff --git a/packages/packsquash/benches/benches.rs b/packages/packsquash/benches/benches.rs index 43fb4313f..b193dbd3f 100644 --- a/packages/packsquash/benches/benches.rs +++ b/packages/packsquash/benches/benches.rs @@ -3,7 +3,7 @@ use std::path::Path; use std::time::Duration; -use criterion::{measurement::Measurement, BatchSize, BenchmarkGroup, Criterion, SamplingMode}; +use criterion::{BatchSize, BenchmarkGroup, Criterion, SamplingMode, measurement::Measurement}; #[cfg(all(target_os = "linux", any(target_arch = "x86", target_arch = "x86_64")))] use criterion_perf_events::Perf; use enumset::EnumSet; @@ -16,9 +16,9 @@ use tempfile::NamedTempFile; use pack_dataset::PackDataset; use packsquash::{ + PackSquasher, config::{FileOptions, GlobalOptions, ProcessedSquashOptions, SquashOptions}, - vfs::os_fs::OsFilesystem, - PackSquasher + vfs::os_fs::OsFilesystem }; mod pack_dataset; diff --git a/packages/packsquash/benches/pack_dataset.rs b/packages/packsquash/benches/pack_dataset.rs index 19f652bf5..d0e550211 100644 --- a/packages/packsquash/benches/pack_dataset.rs +++ b/packages/packsquash/benches/pack_dataset.rs @@ -1,12 +1,12 @@ //! Contains the definition of the pack dataset struct. -use std::collections::{hash_map::Entry, HashMap}; +use std::collections::{HashMap, hash_map::Entry}; use std::fs::File; use std::io; use std::path::Path; use tar::Archive; -use tempfile::{tempdir, TempDir}; +use tempfile::{TempDir, tempdir}; use xz2::read::XzDecoder; /// Represents a pack dataset, which provides access to packs in the dataset. diff --git a/packages/packsquash/src/config/mod.rs b/packages/packsquash/src/config/mod.rs index 0cef17ab7..7553e27bd 100644 --- a/packages/packsquash/src/config/mod.rs +++ b/packages/packsquash/src/config/mod.rs @@ -1,6 +1,6 @@ //! Contains the configuration options needed to create a `PackSquasher` run. -use std::num::{NonZeroU16, NonZeroU32, NonZeroU8}; +use std::num::{NonZeroU8, NonZeroU16, NonZeroU32}; use std::thread::available_parallelism; use std::{num::NonZeroUsize, path::PathBuf}; diff --git a/packages/packsquash/src/lib.rs b/packages/packsquash/src/lib.rs index 89c4922f2..4e23dac6d 100644 --- a/packages/packsquash/src/lib.rs +++ b/packages/packsquash/src/lib.rs @@ -13,18 +13,18 @@ use std::convert::Infallible; use std::io::ErrorKind; use std::panic; use std::pin::Pin; -use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; +use std::sync::atomic::{AtomicBool, Ordering}; use std::{io, time::SystemTime}; use enumset::EnumSet; -use futures::future; use futures::StreamExt; +use futures::future; use thiserror::Error; use tokio::io::AsyncSeek; use tokio::io::BufReader; -use tokio::sync::mpsc::Sender; use tokio::sync::Semaphore; +use tokio::sync::mpsc::Sender; use tokio::{fs::File, io::AsyncRead, runtime::Builder}; use config::ProcessedSquashOptions; @@ -38,12 +38,12 @@ use crate::config::{ CommandFunctionFileOptions, FileOptions, JsonFileOptions, LegacyLanguageFileOptions, PngFileOptions, ShaderFileOptions, SquashOptions }; +use crate::pack_file::PackFileProcessData; use crate::pack_file::asset_type::{ - tweak_asset_types_mask_from_global_options, PackFileAssetTypeMatcher, PackFileAssetTypeMatches + PackFileAssetTypeMatcher, PackFileAssetTypeMatches, tweak_asset_types_mask_from_global_options }; -use crate::pack_file::PackFileProcessData; pub use crate::squash_zip::relative_path::RelativePath; -use crate::squash_zip::{system_id, PreviousZipParseError}; +use crate::squash_zip::{PreviousZipParseError, system_id}; use crate::vfs::{IteratorTraversalOptions, VfsPackFileIterEntry, VirtualFileSystem}; pub mod config; diff --git a/packages/packsquash/src/pack_file/asset_type.rs b/packages/packsquash/src/pack_file/asset_type.rs index f8881882a..d1b470c5e 100644 --- a/packages/packsquash/src/pack_file/asset_type.rs +++ b/packages/packsquash/src/pack_file/asset_type.rs @@ -20,8 +20,8 @@ use crate::pack_file::properties_file::PropertiesFile; use crate::pack_file::shader_file::ShaderFile; use crate::squash_zip::FileListingCircumstances; use crate::{ - config::{compile_pack_file_glob_pattern, CustomFileOptions, FileOptions}, - RelativePath + RelativePath, + config::{CustomFileOptions, FileOptions, compile_pack_file_glob_pattern} }; use super::{AsyncReadAndSizeHint, PackFile, PackFileConstructor, PackFileProcessData}; diff --git a/packages/packsquash/src/pack_file/audio_file.rs b/packages/packsquash/src/pack_file/audio_file.rs index 4fc35c8f1..1fc5bdec2 100644 --- a/packages/packsquash/src/pack_file/audio_file.rs +++ b/packages/packsquash/src/pack_file/audio_file.rs @@ -17,8 +17,8 @@ use tokio_util::codec::{Decoder, FramedRead}; use vorbis_rs::{VorbisBitrateManagementStrategy, VorbisEncoderBuilder}; use crate::config::{AudioBitrateControlMode, AudioFileOptions, ChannelMixingOption}; -use crate::pack_file::asset_type::PackFileAssetType; use crate::pack_file::AsyncReadAndSizeHint; +use crate::pack_file::asset_type::PackFileAssetType; use signal_processor::decode_and_process_sample_blocks; use vorbis_stream_mangler::ValidatingAndObfuscatingOggVorbisStreamMangler; @@ -80,15 +80,21 @@ pub enum OptimizationError { Symphonia(#[from] symphonia::core::errors::Error), #[error("Vorbis error: {0}")] Vorbis(#[from] vorbis_rs::VorbisError), - #[error("Could not find a decodable audio track. Is this file in a supported format, and its extension correct?")] + #[error( + "Could not find a decodable audio track. Is this file in a supported format, and its extension correct?" + )] NoAudioTrack, #[error("Unknown or invalid channel count. Minecraft only supports mono and stereo sounds")] UnsupportedChannelCount, #[error("Unknown sampling frequency. Is this file corrupt?")] UnknownSamplingFrequency, - #[error("Tried to resample from {sampling_frequency} Hz, but that frequency is too high. Please lower it")] + #[error( + "Tried to resample from {sampling_frequency} Hz, but that frequency is too high. Please lower it" + )] InvalidSourceSamplingFrequency { sampling_frequency: NonZeroU32 }, - #[error("Tried to resample to {sampling_frequency} Hz, but that frequency is too high. Please lower it")] + #[error( + "Tried to resample to {sampling_frequency} Hz, but that frequency is too high. Please lower it" + )] InvalidTargetSamplingFrequency { sampling_frequency: NonZeroU32 }, #[error("An invalid target bitrate was specified in the options")] InvalidTargetBitrate, @@ -96,7 +102,9 @@ pub enum OptimizationError { ResamplingFailure(#[from] ResampleError), #[error("{0}")] TwoPassOptimization(#[from] ogg_to_ogg::RemuxError), - #[error("The Minecraft sample count limit for audio files was exceeded. Please reduce the sampling frequency or duration")] + #[error( + "The Minecraft sample count limit for audio files was exceeded. Please reduce the sampling frequency or duration" + )] TooLongForMinecraft, #[error("I/O error: {0}")] Io(#[from] std::io::Error) diff --git a/packages/packsquash/src/pack_file/audio_file/signal_processor.rs b/packages/packsquash/src/pack_file/audio_file/signal_processor.rs index 5423f6d51..590ae5b99 100644 --- a/packages/packsquash/src/pack_file/audio_file/signal_processor.rs +++ b/packages/packsquash/src/pack_file/audio_file/signal_processor.rs @@ -8,9 +8,9 @@ use dasp_interpolate::sinc::Sinc; use dasp_signal::Signal; use rubato::{FftFixedIn, Resampler}; use std::io::{ErrorKind, Read}; -use std::num::{NonZeroU32, NonZeroU8}; +use std::num::{NonZeroU8, NonZeroU32}; use symphonia::core::audio::SampleBuffer; -use symphonia::core::codecs::{Decoder, DecoderOptions, CODEC_TYPE_NULL}; +use symphonia::core::codecs::{CODEC_TYPE_NULL, Decoder, DecoderOptions}; use symphonia::core::formats::{FormatOptions, FormatReader}; use symphonia::core::io::{MediaSourceStream, MediaSourceStreamOptions, ReadOnlySource}; use symphonia::core::meta::{Limit, MetadataOptions}; diff --git a/packages/packsquash/src/pack_file/command_function_file.rs b/packages/packsquash/src/pack_file/command_function_file.rs index 4e49931fc..bca7c3903 100644 --- a/packages/packsquash/src/pack_file/command_function_file.rs +++ b/packages/packsquash/src/pack_file/command_function_file.rs @@ -1,13 +1,13 @@ -use futures::{future, StreamExt}; +use futures::{StreamExt, future}; use thiserror::Error; use tokio::io::AsyncRead; use tokio_stream::Stream; use tokio_util::codec::{FramedRead, LinesCodec, LinesCodecError}; use crate::config::CommandFunctionFileOptions; -use crate::pack_file::asset_type::PackFileAssetType; -use crate::pack_file::util::{prepare_line_for_output, LineNumber, MarkLastDecorator, BOM}; use crate::pack_file::AsyncReadAndSizeHint; +use crate::pack_file::asset_type::PackFileAssetType; +use crate::pack_file::util::{BOM, LineNumber, MarkLastDecorator, prepare_line_for_output}; use super::{OptimizedBytesChunk, PackFile, PackFileConstructor}; diff --git a/packages/packsquash/src/pack_file/json_file.rs b/packages/packsquash/src/pack_file/json_file.rs index b2f728964..a029dbd7a 100644 --- a/packages/packsquash/src/pack_file/json_file.rs +++ b/packages/packsquash/src/pack_file/json_file.rs @@ -10,10 +10,10 @@ use tokio::io::AsyncRead; use tokio_util::codec::{Decoder, FramedRead}; use crate::config::JsonFileOptions; -use crate::pack_file::asset_type::PackFileAssetType; use crate::pack_file::AsyncReadAndSizeHint; +use crate::pack_file::asset_type::PackFileAssetType; -use super::{util::strip_utf8_bom, PackFile, PackFileConstructor}; +use super::{PackFile, PackFileConstructor, util::strip_utf8_bom}; use self::debloater::Debloater; diff --git a/packages/packsquash/src/pack_file/legacy_lang_file.rs b/packages/packsquash/src/pack_file/legacy_lang_file.rs index e208cfad5..936da9a78 100644 --- a/packages/packsquash/src/pack_file/legacy_lang_file.rs +++ b/packages/packsquash/src/pack_file/legacy_lang_file.rs @@ -1,6 +1,6 @@ use std::sync::LazyLock; -use futures::{future, StreamExt}; +use futures::{StreamExt, future}; use patricia_tree::PatriciaSet; use regex::Regex; use thiserror::Error; @@ -9,9 +9,9 @@ use tokio_stream::Stream; use tokio_util::codec::{FramedRead, LinesCodec, LinesCodecError}; use crate::config::LegacyLanguageFileOptions; -use crate::pack_file::asset_type::PackFileAssetType; -use crate::pack_file::util::{prepare_line_for_output, LineNumber, MarkLastDecorator, BOM}; use crate::pack_file::AsyncReadAndSizeHint; +use crate::pack_file::asset_type::PackFileAssetType; +use crate::pack_file::util::{BOM, LineNumber, MarkLastDecorator, prepare_line_for_output}; use super::{OptimizedBytesChunk, PackFile, PackFileConstructor}; diff --git a/packages/packsquash/src/pack_file/passthrough_file.rs b/packages/packsquash/src/pack_file/passthrough_file.rs index a0d8d2697..01c32f3e5 100644 --- a/packages/packsquash/src/pack_file/passthrough_file.rs +++ b/packages/packsquash/src/pack_file/passthrough_file.rs @@ -50,12 +50,9 @@ impl PackFile for PassthroughFile { type OptimizedByteChunksStream = FramedRead; fn process(self) -> FramedRead { - FramedRead::new( - self.read, - PassthroughDecoder { - optimization_strategy_message: self.optimization_strategy_message - } - ) + FramedRead::new(self.read, PassthroughDecoder { + optimization_strategy_message: self.optimization_strategy_message + }) } fn is_compressed(&self) -> bool { diff --git a/packages/packsquash/src/pack_file/png_file/image_processor.rs b/packages/packsquash/src/pack_file/png_file/image_processor.rs index e40fb6d5a..5555e518b 100644 --- a/packages/packsquash/src/pack_file/png_file/image_processor.rs +++ b/packages/packsquash/src/pack_file/png_file/image_processor.rs @@ -3,14 +3,14 @@ use crate::config::ColorQuantizationTarget; use crate::zopfli_iterations_time_model::ZopfliIterationsTimeModel; use bytes::BytesMut; -use imagequant::{liq_error, Attributes}; +use imagequant::{Attributes, liq_error}; use itertools::Itertools; use obfstr::random; -use oxipng::{indexset, BitDepth, ColorType, Deflaters, Options, RowFilter, StripChunks}; +use oxipng::{BitDepth, ColorType, Deflaters, Options, RowFilter, StripChunks, indexset}; use rgb::{AsPixels, RGBA8}; use spng::{ContextFlags, DecodeFlags, Format}; use std::io::Read; -use std::num::{NonZeroU16, NonZeroU8}; +use std::num::{NonZeroU8, NonZeroU16}; use std::time::Duration; use std::{cmp, iter}; use thiserror::Error; @@ -131,20 +131,12 @@ pub fn obfuscate_png(png: &mut [u8]) { const CRC32_KEY: u32 = { let k = random!(u32); - if k == 0 { - 0xCAFEBABE - } else { - k - } + if k == 0 { 0xCAFEBABE } else { k } }; const ADLER32_KEY: u32 = { let k = random!(u32); - if k == 0 { - 0xCAFEBABE - } else { - k - } + if k == 0 { 0xCAFEBABE } else { k } }; let mut i = 8; diff --git a/packages/packsquash/src/pack_file/shader_file/parser.rs b/packages/packsquash/src/pack_file/shader_file/parser.rs index 641fbde87..9e798f399 100644 --- a/packages/packsquash/src/pack_file/shader_file/parser.rs +++ b/packages/packsquash/src/pack_file/shader_file/parser.rs @@ -7,9 +7,9 @@ use glsl_lang::ast::{ }; use glsl_lang::parse::{Extractable, Parse}; use glsl_lang::transpiler::glsl::{FormattingSettings, FormattingState}; -use glsl_lang_lexer::v2_full::fs::PreprocessorExt; -use glsl_lang_lexer::v2_full::LexicalError; use glsl_lang_lexer::ParseOptions; +use glsl_lang_lexer::v2_full::LexicalError; +use glsl_lang_lexer::v2_full::fs::PreprocessorExt; use glsl_lang_pp::processor::fs::{FileSystem, Processor}; use regex::Regex; use std::any::TypeId; diff --git a/packages/packsquash/src/pack_meta.rs b/packages/packsquash/src/pack_meta.rs index 5b01a1bce..6d02ac6c1 100644 --- a/packages/packsquash/src/pack_meta.rs +++ b/packages/packsquash/src/pack_meta.rs @@ -110,7 +110,7 @@ impl PackMeta { _ => { return Err(PackMetaError::MalformedMeta( PACK_FORMAT_VERSION_IS_NOT_INTEGER - )) + )); } }; @@ -125,26 +125,26 @@ impl PackMeta { Some(_) => { return Err(PackMetaError::MalformedMeta( "The \"description\" key value is not a text component" - )) + )); } None => { return Err(PackMetaError::MalformedMeta( "Missing \"description\" key in pack metadata object" - )) + )); } }; } _ => { return Err(PackMetaError::MalformedMeta( "The \"pack\" key value is not a JSON object" - )) + )); } } } _ => { return Err(PackMetaError::MalformedMeta( "The JSON value is not an object" - )) + )); } }; diff --git a/packages/packsquash/src/squash_zip.rs b/packages/packsquash/src/squash_zip.rs index 77a5cb554..4d61c6bc9 100644 --- a/packages/packsquash/src/squash_zip.rs +++ b/packages/packsquash/src/squash_zip.rs @@ -13,7 +13,7 @@ use std::{ use aes::Aes128; use ahash::AHashMap; -use futures::{future, StreamExt, TryStreamExt}; +use futures::{StreamExt, TryStreamExt, future}; use thiserror::Error; use tokio::{ fs::File, @@ -25,7 +25,7 @@ use tokio_util::io::ReaderStream; use zopfli::Format; use crate::{ - config::PercentageInteger, zopfli_iterations_time_model::ZopfliIterationsTimeModel, RelativePath + RelativePath, config::PercentageInteger, zopfli_iterations_time_model::ZopfliIterationsTimeModel }; use self::{ @@ -1015,17 +1015,14 @@ async fn read_previous_zip_contents( } // After all this work, we can finally insert the file data in the map :) - previous_zip_contents.insert( - relative_path, - PreviousFile { - squash_time, - data_offset: local_file_header_offset + 30 + local_header_file_name_length, - crc32: crc, - compression_method, - uncompressed_size, - compressed_size - } - ); + previous_zip_contents.insert(relative_path, PreviousFile { + squash_time, + data_offset: local_file_header_offset + 30 + local_header_file_name_length, + crc32: crc, + compression_method, + uncompressed_size, + compressed_size + }); // Make sure the seek position points to the next central directory header for the // next iteration diff --git a/packages/packsquash/src/squash_zip/obfuscation_engine.rs b/packages/packsquash/src/squash_zip/obfuscation_engine.rs index b6fc85c9f..32c300294 100644 --- a/packages/packsquash/src/squash_zip/obfuscation_engine.rs +++ b/packages/packsquash/src/squash_zip/obfuscation_engine.rs @@ -10,8 +10,8 @@ use obfstr::random; use rand_xoshiro::{ - rand_core::{RngCore, SeedableRng}, - Xoshiro128Plus + Xoshiro128Plus, + rand_core::{RngCore, SeedableRng} }; use std::{ borrow::Cow, @@ -24,13 +24,13 @@ use tokio::io::{AsyncWrite, AsyncWriteExt}; pub use self::pseudodir_concealment::FileListingCircumstances; use self::pseudodir_concealment::PseudodirConcealer; -use crate::{config::PercentageInteger, RelativePath}; +use crate::{RelativePath, config::PercentageInteger}; use super::{ + SquashZipSettings, zip_file_record::{ CentralDirectoryHeader, CompressionMethod, EndOfCentralDirectory, LocalFileHeader - }, - SquashZipSettings + } }; mod pseudodir_concealment; @@ -38,11 +38,7 @@ mod pseudodir_concealment; const CRC32_KEY: u32 = { let k = random!(u32); - if k == 0 { - 0xDEADBEEF - } else { - k - } + if k == 0 { 0xDEADBEEF } else { k } }; enum SizeIncreasingObfuscation { diff --git a/packages/packsquash/src/squash_zip/obfuscation_engine/pseudodir_concealment.rs b/packages/packsquash/src/squash_zip/obfuscation_engine/pseudodir_concealment.rs index ceb4ca43b..3952454bb 100644 --- a/packages/packsquash/src/squash_zip/obfuscation_engine/pseudodir_concealment.rs +++ b/packages/packsquash/src/squash_zip/obfuscation_engine/pseudodir_concealment.rs @@ -1,4 +1,4 @@ -use crate::{config::compile_pack_file_glob_pattern, RelativePath}; +use crate::{RelativePath, config::compile_pack_file_glob_pattern}; use globset::{GlobSet, GlobSetBuilder}; static KNOWN_LISTED_RESOURCE_PATTERNS: &[&str] = &[ diff --git a/packages/packsquash/src/squash_zip/relative_path.rs b/packages/packsquash/src/squash_zip/relative_path.rs index 4c37846ed..896c321ea 100644 --- a/packages/packsquash/src/squash_zip/relative_path.rs +++ b/packages/packsquash/src/squash_zip/relative_path.rs @@ -5,7 +5,7 @@ use std::{ borrow::Cow, io, ops::Deref, - path::{Path, MAIN_SEPARATOR} + path::{MAIN_SEPARATOR, Path} }; use thiserror::Error; @@ -38,15 +38,12 @@ pub enum InvalidPathError<'a> { impl From> for io::Error { fn from(error: InvalidPathError<'_>) -> Self { - io::Error::new( - io::ErrorKind::Other, - match error { - InvalidPathError::NonUnicode(error_message) => { - InvalidPathError::NonUnicode(Cow::Owned(error_message.into_owned())) - } - InvalidPathError::TooBig => InvalidPathError::TooBig + io::Error::new(io::ErrorKind::Other, match error { + InvalidPathError::NonUnicode(error_message) => { + InvalidPathError::NonUnicode(Cow::Owned(error_message.into_owned())) } - ) + InvalidPathError::TooBig => InvalidPathError::TooBig + }) } } diff --git a/packages/packsquash/src/squash_zip/system_id.rs b/packages/packsquash/src/squash_zip/system_id.rs index 6332a52d9..138641f35 100644 --- a/packages/packsquash/src/squash_zip/system_id.rs +++ b/packages/packsquash/src/squash_zip/system_id.rs @@ -26,8 +26,7 @@ mod os; mod tests; /// The panic error message to show in case a system ID could not be found. -static ERROR_MESSAGE: &str = - "Couldn't get a suitable system ID for ZIP field obfuscation. Aborting execution for safety. \ +static ERROR_MESSAGE: &str = "Couldn't get a suitable system ID for ZIP field obfuscation. Aborting execution for safety. \ Please review your system configuration or report a bug."; /// A struct that contains a system ID and some of its most relevant characteristics. diff --git a/packages/packsquash/src/squash_zip/system_id/os.rs b/packages/packsquash/src/squash_zip/system_id/os.rs index 8969cb3f8..b6b427d06 100644 --- a/packages/packsquash/src/squash_zip/system_id/os.rs +++ b/packages/packsquash/src/squash_zip/system_id/os.rs @@ -198,7 +198,7 @@ pub(super) fn get_dmi_product_id() -> Option { #[allow(unsafe_code, non_camel_case_types)] pub(super) fn get_platform_serial_number() -> Option { use core_foundation::{ - base::{kCFAllocatorDefault, mach_port_t, CFAllocatorRef, CFTypeRef, TCFType}, + base::{CFAllocatorRef, CFTypeRef, TCFType, kCFAllocatorDefault, mach_port_t}, dictionary::{CFDictionaryRef, CFMutableDictionaryRef}, string::{CFString, CFStringRef} }; @@ -305,7 +305,8 @@ pub(super) fn get_platform_serial_number() -> Option { pub(super) fn get_host_id() -> Option { use std::os::raw::c_long; - extern "C" { + #[allow(unsafe_code)] + unsafe extern "C" { /// `long gethostid()`, from `#include `. /// /// Documentation: @@ -323,7 +324,7 @@ pub(super) fn get_host_id() -> Option { #[cfg(windows)] pub(super) fn get_machine_id() -> Option { use uuid::Uuid; - use winreg::{enums::HKEY_LOCAL_MACHINE, RegKey}; + use winreg::{RegKey, enums::HKEY_LOCAL_MACHINE}; let machine_guid: String = RegKey::predef(HKEY_LOCAL_MACHINE) .open_subkey("SOFTWARE\\Microsoft\\Cryptography") @@ -370,7 +371,7 @@ pub(super) fn get_product_id() -> Option { /// and, because it is 32-bit long, it is pretty weak. Use as a last-resort fallback. #[cfg(windows)] pub(super) fn get_install_date() -> Option { - use winreg::{enums::HKEY_LOCAL_MACHINE, RegKey}; + use winreg::{RegKey, enums::HKEY_LOCAL_MACHINE}; let install_date: u32 = RegKey::predef(HKEY_LOCAL_MACHINE) .open_subkey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion") diff --git a/packages/packsquash/src/squash_zip/system_time_sanitizer.rs b/packages/packsquash/src/squash_zip/system_time_sanitizer.rs index 7d2b5e8e5..219176921 100644 --- a/packages/packsquash/src/squash_zip/system_time_sanitizer.rs +++ b/packages/packsquash/src/squash_zip/system_time_sanitizer.rs @@ -5,8 +5,8 @@ use std::time::{Duration, SystemTime, SystemTimeError}; use aes::cipher::generic_array::GenericArray; use aes::{ - cipher::{BlockCipher, BlockEncrypt, KeyInit}, - Aes128, Block + Aes128, Block, + cipher::{BlockCipher, BlockEncrypt, KeyInit} }; use fpe::ff1::{BinaryNumeralString, FF1}; diff --git a/packages/packsquash/src/squash_zip/tests.rs b/packages/packsquash/src/squash_zip/tests.rs index 1e81ebeb1..f39be0f0f 100644 --- a/packages/packsquash/src/squash_zip/tests.rs +++ b/packages/packsquash/src/squash_zip/tests.rs @@ -58,19 +58,16 @@ async fn add_files_finish_and_read_back_test( spool_buffer_size: Option ) -> PathBuf { let squash_zip = squash_zip.unwrap_or( - SquashZip::new( - None, - SquashZipSettings { - zopfli_iterations: 20, - store_squash_time: true, - enable_obfuscation: false, - enable_deduplication, - enable_size_increasing_obfuscation: false, - percentage_of_records_tuned_for_obfuscation_discretion: 0.try_into().unwrap(), - workaround_old_java_obfuscation_quirks: false, - spool_buffer_size: spool_buffer_size.unwrap_or(DEFAULT_SPOOL_BUFFER_SIZE) - } - ) + SquashZip::new(None, SquashZipSettings { + zopfli_iterations: 20, + store_squash_time: true, + enable_obfuscation: false, + enable_deduplication, + enable_size_increasing_obfuscation: false, + percentage_of_records_tuned_for_obfuscation_discretion: 0.try_into().unwrap(), + workaround_old_java_obfuscation_quirks: false, + spool_buffer_size: spool_buffer_size.unwrap_or(DEFAULT_SPOOL_BUFFER_SIZE) + }) .await .map_err(|(err, _)| err) .expect(INSTANTIATION_FAILURE) @@ -396,19 +393,16 @@ async fn add_several_finish_then_reuse_and_add_works() { #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn several_files_with_same_path_are_handled_properly() { - let squash_zip = SquashZip::new( - None::, - SquashZipSettings { - zopfli_iterations: 0, - store_squash_time: false, - enable_obfuscation: false, - enable_deduplication: false, - enable_size_increasing_obfuscation: false, - percentage_of_records_tuned_for_obfuscation_discretion: 0.try_into().unwrap(), - workaround_old_java_obfuscation_quirks: false, - spool_buffer_size: DEFAULT_SPOOL_BUFFER_SIZE - } - ) + let squash_zip = SquashZip::new(None::, SquashZipSettings { + zopfli_iterations: 0, + store_squash_time: false, + enable_obfuscation: false, + enable_deduplication: false, + enable_size_increasing_obfuscation: false, + percentage_of_records_tuned_for_obfuscation_discretion: 0.try_into().unwrap(), + workaround_old_java_obfuscation_quirks: false, + spool_buffer_size: DEFAULT_SPOOL_BUFFER_SIZE + }) .await .map_err(|(err, _)| err) .expect(INSTANTIATION_FAILURE); diff --git a/packages/packsquash/src/vfs/os_fs.rs b/packages/packsquash/src/vfs/os_fs.rs index 12e744936..73f5fe392 100644 --- a/packages/packsquash/src/vfs/os_fs.rs +++ b/packages/packsquash/src/vfs/os_fs.rs @@ -154,23 +154,22 @@ mod tests { File::create(file3_path).expect("I/O operations are assumed not to fail during tests"); } - let file_iter = OsFilesystem.file_iterator( - root_dir.path(), - IteratorTraversalOptions { - ignore_system_and_hidden_files: true - } - ); + let file_iter = OsFilesystem.file_iterator(root_dir.path(), IteratorTraversalOptions { + ignore_system_and_hidden_files: true + }); const RELATIVE_PATHS: &[&str] = &["hello/world.txt", "bye/bye/now.txt"]; let mut file_count = 0; for file in file_iter { - assert!(RELATIVE_PATHS.contains( - &file - .expect("I/O operations are assumed not to fail during tests") - .relative_path - .as_str() - )); + assert!( + RELATIVE_PATHS.contains( + &file + .expect("I/O operations are assumed not to fail during tests") + .relative_path + .as_str() + ) + ); file_count += 1; } @@ -184,12 +183,9 @@ mod tests { #[test] fn single_component_dot_relative_path_works() { - let mut file_iter = OsFilesystem.file_iterator( - Path::new("."), - IteratorTraversalOptions { - ignore_system_and_hidden_files: true - } - ); + let mut file_iter = OsFilesystem.file_iterator(Path::new("."), IteratorTraversalOptions { + ignore_system_and_hidden_files: true + }); assert!( file_iter.next().is_some(), @@ -199,12 +195,9 @@ mod tests { #[test] fn single_component_double_dot_relative_path_works() { - let mut file_iter = OsFilesystem.file_iterator( - Path::new(".."), - IteratorTraversalOptions { - ignore_system_and_hidden_files: true - } - ); + let mut file_iter = OsFilesystem.file_iterator(Path::new(".."), IteratorTraversalOptions { + ignore_system_and_hidden_files: true + }); assert!( file_iter.next().is_some(), @@ -222,12 +215,9 @@ mod tests { let file_path = root_dir.path().join("file.bin"); File::create(file_path).expect("I/O operations are assumed not to fail during tests"); - let file_iter = OsFilesystem.file_iterator( - root_dir.path(), - IteratorTraversalOptions { - ignore_system_and_hidden_files: true - } - ); + let file_iter = OsFilesystem.file_iterator(root_dir.path(), IteratorTraversalOptions { + ignore_system_and_hidden_files: true + }); assert_eq!( file_iter.count(), diff --git a/packages/packsquash_cli/Cargo.toml b/packages/packsquash_cli/Cargo.toml index b95e70424..4499635e2 100644 --- a/packages/packsquash_cli/Cargo.toml +++ b/packages/packsquash_cli/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "packsquash_cli" description = "Minecraft resource and data pack optimizer (CLI)" -version = "0.4.0" +version.workspace = true authors = ["Alejandro \"AlexTMjugador\" González"] -repository = "https://github.com/ComunidadAylas/PackSquash" -license = "AGPL-3.0-or-later" +repository.workspace = true +license.workspace = true readme = "../../README.md" publish = false -edition = "2021" +edition.workspace = true [dependencies] packsquash = { path = "../packsquash", version = "0.4.0" } diff --git a/packages/packsquash_cli/src/bin/packsquash/main.rs b/packages/packsquash_cli/src/bin/packsquash/main.rs index 8a045bbf9..6b308550f 100644 --- a/packages/packsquash_cli/src/bin/packsquash/main.rs +++ b/packages/packsquash_cli/src/bin/packsquash/main.rs @@ -13,10 +13,10 @@ use std::{ use env_logger::{Builder, Target, WriteStyle}; use getopts::{Options, ParsingStyle}; -use log::{debug, error, info, trace, warn, Level, LevelFilter}; +use log::{Level, LevelFilter, debug, error, info, trace, warn}; use packsquash::{ - config::SquashOptions, vfs::os_fs::OsFilesystem, PackSquasher, PackSquasherError, - PackSquasherStatus, PackSquasherWarning + PackSquasher, PackSquasherError, PackSquasherStatus, PackSquasherWarning, config::SquashOptions, + vfs::os_fs::OsFilesystem }; use terminal_style::{environment_allows_color, environment_allows_emoji}; use terminal_title_controller::TerminalTitleController; diff --git a/packages/packsquash_cli/src/bin/packsquash/terminal_title_setter/unix.rs b/packages/packsquash_cli/src/bin/packsquash/terminal_title_setter/unix.rs index b7e6d6cc7..e20653a7a 100644 --- a/packages/packsquash_cli/src/bin/packsquash/terminal_title_setter/unix.rs +++ b/packages/packsquash_cli/src/bin/packsquash/terminal_title_setter/unix.rs @@ -1,4 +1,4 @@ -use super::{write_ansi_set_window_title_escape_sequence, TerminalTitleSetterTrait}; +use super::{TerminalTitleSetterTrait, write_ansi_set_window_title_escape_sequence}; use std::fs::{File, OpenOptions}; use std::path::PathBuf; use std::{ @@ -83,7 +83,8 @@ fn controlling_terminal() -> Option { use std::ffi::CStr; use std::os::raw::c_char; - extern "C" { + #[allow(unsafe_code)] + unsafe extern "C" { /// `char* ctermid(char* s)`, from `#include `. /// /// Documentation: diff --git a/packages/packsquash_cli/src/bin/packsquash/terminal_title_setter/windows.rs b/packages/packsquash_cli/src/bin/packsquash/terminal_title_setter/windows.rs index 651484bb3..0b70fae47 100644 --- a/packages/packsquash_cli/src/bin/packsquash/terminal_title_setter/windows.rs +++ b/packages/packsquash_cli/src/bin/packsquash/terminal_title_setter/windows.rs @@ -7,7 +7,7 @@ use std::{env, io}; use winapi_util::console::Console; use windows_sys::Win32::System::Console::SetConsoleTitleW; -use super::{write_ansi_set_window_title_escape_sequence, TerminalTitleSetterTrait}; +use super::{TerminalTitleSetterTrait, write_ansi_set_window_title_escape_sequence}; /// A terminal output stream. enum TerminalStream {