From 40648155f7a7878fb7c61b869574b5ec9de581e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20du=20Garreau?= Date: Fri, 5 Apr 2024 16:28:49 +0200 Subject: [PATCH] Repair CI --- .github/workflows/ci.yaml | 71 ++++++++++++--------------------------- src/cp437.rs | 2 +- src/read.rs | 6 ++-- src/read/stream.rs | 3 +- src/unstable.rs | 4 +-- src/write.rs | 14 +++++--- tests/zip_crypto.rs | 10 ++++-- 7 files changed, 45 insertions(+), 65 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 35d4a6e99..381bec37f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -16,77 +16,50 @@ jobs: strategy: matrix: os: [ubuntu-latest, macOS-latest, windows-latest] - rust: [stable, 1.59.0] + rust: [stable, 1.59] steps: - - uses: actions/checkout@master + - uses: actions/checkout@v4 - name: Install ${{ matrix.rust }} - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.rust }} - override: true - - - name: check - uses: actions-rs/cargo@v1 - with: - command: check - args: --all --bins --examples - - - name: tests - uses: actions-rs/cargo@v1 - with: - command: test - args: --all + run: rustup install ${{ matrix.rust }} && rustup default ${{ matrix.rust }} + + - name: Downgrade dependencies for MSRV + if: ${{ matrix.rust == '1.59' }} + run: | + cargo update -p byteorder --precise 1.4.3 + cargo update -p jobserver --precise 0.1.26 + cargo update -p base64ct --precise 1.5.3 + + - run: cargo check --all --bins --examples + - run: cargo test --all clippy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true - components: clippy - - - name: clippy - uses: actions-rs/cargo@v1 - with: - command: clippy - args: --all-targets --all-features -- -D warnings + - run: cargo clippy --all-targets --all-features check_fmt_and_docs: name: Checking fmt and docs runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly - components: rustfmt, clippy - override: true - - name: fmt - run: cargo fmt --all -- --check + steps: + - uses: actions/checkout@v4 - - name: Docs - run: cargo doc + - run: cargo fmt --all -- --check + - run: cargo doc fuzz: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true - + - uses: actions/checkout@v4 + - run: rustup install nightly --profile minimal && rustup default nightly - run: cargo install cargo-fuzz + - name: compile fuzz run: | cargo fuzz build fuzz_read diff --git a/src/cp437.rs b/src/cp437.rs index 4dba9af12..4e31dbfcd 100644 --- a/src/cp437.rs +++ b/src/cp437.rs @@ -189,7 +189,7 @@ mod test { #[test] fn example_slice() { use super::FromCp437; - let data = b"Cura\x87ao"; + let data = std::convert::identity(b"Cura\x87ao"); // identity to avoid a lint from rustc assert!(::std::str::from_utf8(data).is_err()); assert_eq!(data.from_cp437(), "CuraƧao"); } diff --git a/src/read.rs b/src/read.rs index b702b4f21..aa39ad153 100644 --- a/src/read.rs +++ b/src/read.rs @@ -935,8 +935,7 @@ impl<'a> ZipFile<'a> { pub fn is_dir(&self) -> bool { self.name() .chars() - .rev() - .next() + .next_back() .map_or(false, |c| c == '/' || c == '\\') } @@ -991,7 +990,7 @@ impl<'a> Drop for ZipFile<'a> { // Get the inner `Take` reader so all decryption, decompression and CRC calculation is skipped. let mut reader: std::io::Take<&mut dyn std::io::Read> = match &mut self.reader { ZipFileReader::NoReader => { - let innerreader = ::std::mem::replace(&mut self.crypto_reader, None); + let innerreader = self.crypto_reader.take(); innerreader.expect("Invalid reader state").into_inner() } reader => { @@ -1000,6 +999,7 @@ impl<'a> Drop for ZipFile<'a> { } }; + #[allow(clippy::unused_io_amount)] loop { match reader.read(&mut buffer) { Ok(0) => break, diff --git a/src/read/stream.rs b/src/read/stream.rs index 5a01b23f9..dc967ee89 100644 --- a/src/read/stream.rs +++ b/src/read/stream.rs @@ -184,8 +184,7 @@ impl ZipStreamFileMetadata { pub fn is_dir(&self) -> bool { self.name() .chars() - .rev() - .next() + .next_back() .map_or(false, |c| c == '/' || c == '\\') } diff --git a/src/unstable.rs b/src/unstable.rs index f8b46a970..cc03ff9a0 100644 --- a/src/unstable.rs +++ b/src/unstable.rs @@ -8,7 +8,7 @@ pub mod write { /// Unstable methods for [`FileOptions`]. pub trait FileOptionsExt { /// Write the file with the given password using the deprecated ZipCrypto algorithm. - /// + /// /// This is not recommended for new archives, as ZipCrypto is not secure. fn with_deprecated_encryption(self, password: &[u8]) -> Self; } @@ -17,4 +17,4 @@ pub mod write { self.with_deprecated_encryption(password) } } -} \ No newline at end of file +} diff --git a/src/write.rs b/src/write.rs index 4cdc031b0..63a4b3792 100644 --- a/src/write.rs +++ b/src/write.rs @@ -7,7 +7,6 @@ use crate::spec; use crate::types::{AtomicU64, DateTime, System, ZipFileData, DEFAULT_VERSION}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use crc32fast::Hasher; -use std::convert::TryInto; use std::default::Default; use std::io; use std::io::prelude::*; @@ -410,8 +409,12 @@ impl ZipWriter { self.files.push(file); } if let Some(keys) = options.encrypt_with { - let mut zipwriter = crate::zipcrypto::ZipCryptoWriter { writer: core::mem::replace(&mut self.inner, GenericZipWriter::Closed).unwrap(), buffer: vec![], keys }; - let mut crypto_header = [0u8; 12]; + let mut zipwriter = crate::zipcrypto::ZipCryptoWriter { + writer: core::mem::replace(&mut self.inner, GenericZipWriter::Closed).unwrap(), + buffer: vec![], + keys, + }; + let crypto_header = [0u8; 12]; zipwriter.write_all(&crypto_header)?; self.inner = GenericZipWriter::Storer(MaybeEncrypted::Encrypted(zipwriter)); @@ -428,10 +431,11 @@ impl ZipWriter { match core::mem::replace(&mut self.inner, GenericZipWriter::Closed) { GenericZipWriter::Storer(MaybeEncrypted::Encrypted(writer)) => { let crc32 = self.stats.hasher.clone().finalize(); - self.inner = GenericZipWriter::Storer(MaybeEncrypted::Unencrypted(writer.finish(crc32)?)) + self.inner = + GenericZipWriter::Storer(MaybeEncrypted::Unencrypted(writer.finish(crc32)?)) } GenericZipWriter::Storer(w) => self.inner = GenericZipWriter::Storer(w), - _ => unreachable!() + _ => unreachable!(), } let writer = self.inner.get_plain(); diff --git a/tests/zip_crypto.rs b/tests/zip_crypto.rs index d831c1e62..a9b96719c 100644 --- a/tests/zip_crypto.rs +++ b/tests/zip_crypto.rs @@ -22,11 +22,16 @@ use std::io::Read; #[test] fn encrypting_file() { - use zip::unstable::write::FileOptionsExt; use std::io::{Read, Write}; + use zip::unstable::write::FileOptionsExt; let mut buf = vec![0; 2048]; let mut archive = zip::write::ZipWriter::new(std::io::Cursor::new(&mut buf)); - archive.start_file("name", zip::write::FileOptions::default().with_deprecated_encryption(b"password")).unwrap(); + archive + .start_file( + "name", + zip::write::FileOptions::default().with_deprecated_encryption(b"password"), + ) + .unwrap(); archive.write_all(b"test").unwrap(); archive.finish().unwrap(); drop(archive); @@ -35,7 +40,6 @@ fn encrypting_file() { let mut buf = Vec::new(); file.read_to_end(&mut buf).unwrap(); assert_eq!(buf, b"test"); - } #[test] fn encrypted_file() {