Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 12, 2025

Migrates gix-archive from the zip crate to rawzip for ZIP archive creation.

Changes

  • Dependencies: Replaced zip = "6.0.0" with rawzip = "0.4.2" and added flate2 to zip feature (required for deflate compression)

  • Archive writing (write.rs):

    • Use rawzip::ZipArchiveWriter with explicit flate2::DeflateEncoder for compression
    • Simplify timestamp handling: UtcDateTime::from_unix(seconds) instead of manual date/time component conversion
    • Ensure directory paths end with / (rawzip requirement)
  • Tests (archive.rs):

    • Update to rawzip's reading API: ZipArchive::from_slice(), mode().is_symlink(), mode().value(), get_entry().data()
    • Adjust size expectations (rawzip produces ~7% larger archives than zip crate)

API differences

// Old (zip crate)
ar.start_file(path, options)?;
ar.add_directory(path, options)?;

// New (rawzip)
let (mut entry, config) = ar.new_file(path).start()?;
let encoder = flate2::write::DeflateEncoder::new(&mut entry, compression);
let mut writer = config.wrap(encoder);
// ... write data ...

ar.new_dir(&format!("{}/", path)).create()?;  // Must end with '/'

All existing tests pass. The zip crate and its transitive dependencies (arbitrary, derive_arbitrary) are removed from the dependency tree.

Original prompt

Replace the zip crate in gix-archive with https://github.com/nickbabcock/rawzip.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Replace zip crate in gix-archive with rawzip Replace zip crate with rawzip in gix-archive Dec 12, 2025
Copilot AI requested a review from Byron December 12, 2025 04:09
Co-authored-by: Byron <63622+Byron@users.noreply.github.com>
@Byron Byron force-pushed the copilot/replace-zip-crate-with-rawzip branch from c04eb69 to c01545f Compare December 19, 2025 12:17
@Byron Byron marked this pull request as ready for review December 19, 2025 12:17
@Byron Byron requested a review from Copilot December 19, 2025 12:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates gix-archive from the zip crate to rawzip for ZIP archive creation, removing transitive dependencies (arbitrary, derive_arbitrary) from the dependency tree.

Key changes:

  • Replaces zip crate with rawzip and uses flate2 directly for deflate compression
  • Updates archive writing to use rawzip's API with explicit compression handling via DeflateEncoder
  • Adjusts tests to use rawzip's reading API and updates size expectations (~7% larger archives)

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

File Description
gix-archive/Cargo.toml Replaces zip dependency with rawzip and adds flate2 to zip feature
Cargo.lock Removes zip, arbitrary, and derive_arbitrary dependencies; adds rawzip
gix-archive/src/write.rs Implements ZIP archive writing using rawzip API with explicit flate2 compression, proper UTF-8 error handling, and ensures directory paths end with /
gix-archive/tests/archive.rs Updates tests to use rawzip's reading API and adjusts size threshold from 1280 to 1400 bytes

ar.start_file(path.to_string(), file_opts)
.map_err(std::io::Error::other)?;
std::io::copy(&mut entry, ar)?;
use bstr::ByteSlice;
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use bstr::ByteSlice; statement is repeated in all three match arms (lines 174, 203, and 224). For better maintainability, consider moving this import to the top of the function, just after line 168, so it's available for all match arms without repetition.

Copilot uses AI. Check for mistakes.
@Byron Byron force-pushed the copilot/replace-zip-crate-with-rawzip branch from c01545f to 1132f57 Compare December 19, 2025 13:01
- cargo fmt
@Byron Byron force-pushed the copilot/replace-zip-crate-with-rawzip branch from 1132f57 to 8c9b4d6 Compare December 19, 2025 13:05
@Byron Byron requested a review from Copilot December 19, 2025 13:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

let path = path.to_str().map_err(|_| {
Error::Io(std::io::Error::new(
std::io::ErrorKind::InvalidData,
format!("Invalid UTF-8 in entry path: {path}"),
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message format string uses the Display implementation for BString, which may not be ideal for debugging UTF-8 issues. Consider using either the Debug formatting with {path:?} to show the raw bytes, or use String::from_utf8_lossy(path.as_ref()) in the error message to show what the path would look like with replacement characters, which would make it easier to identify the problematic characters.

Suggested change
format!("Invalid UTF-8 in entry path: {path}"),
format!("Invalid UTF-8 in entry path: {path:?}"),

Copilot uses AI. Check for mistakes.
Comment on lines 222 to 224
Error::Io(std::io::Error::new(
std::io::ErrorKind::InvalidData,
"Invalid UTF-8 in symlink target",
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message would be more helpful if it included the symlink path and showed what the invalid target looks like. Consider including the symlink path in the error and using String::from_utf8_lossy to show the target with replacement characters for debugging.

Suggested change
Error::Io(std::io::Error::new(
std::io::ErrorKind::InvalidData,
"Invalid UTF-8 in symlink target",
let lossy_target = String::from_utf8_lossy(buf.as_slice());
Error::Io(std::io::Error::new(
std::io::ErrorKind::InvalidData,
format!(
"Invalid UTF-8 in symlink target for entry '{symlink_path}': {lossy_target}"
),

Copilot uses AI. Check for mistakes.
@Byron Byron enabled auto-merge December 19, 2025 15:01
@Byron
Copy link
Member

Byron commented Dec 19, 2025

Related to #2293 .

@Byron Byron merged commit 25099c8 into main Dec 19, 2025
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants