Skip to content

Conversation

@e-nomem
Copy link
Contributor

@e-nomem e-nomem commented Nov 10, 2025

I was thinking that the convenience methods with default implementations available on ModuleWriter shouldn't really be overridden and that implementers of ModuleWriter should only focus on the one primary method. In order to enforce that separation, this PR moves all the convenience methods into a ModuleWriterExt trait that has a blanket implementation for all ModuleWriters.

In addition to that, the following related changes are included:

  • Change the main method to be implemented on ModuleWriter to accept an impl Read instead of a byte slice
  • Related to using an impl Read, add a StreamSha256 struct that calculates the hash as the data is streamed to the underlying Writer
  • Limit the permissions for the files to executable or non-executable (0o755 or 0o644)

The PR is structured so that the individual commits can be reviewed to ensure that there are no behavioral changes.

Comment on lines 1522 to 1518
let source = fs::read_link(file.path())?;
writer.add_file_with_permissions(
relative,
source.parent().unwrap(),
mode,
)?;
writer.add_file_infer_permissions(relative, file.path())?;
Copy link
Contributor Author

@e-nomem e-nomem Nov 10, 2025

Choose a reason for hiding this comment

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

This is the only change I'm uncertain about. I'm passing file.path() here as the source so that the permission can be checked, but previously the code used to pass in the parent directory as the source. It's not clear to me why.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about this either. cc @konstin

@messense messense requested a review from Copilot November 11, 2025 11:01
Copilot finished reviewing on behalf of messense November 11, 2025 11:06
Copy link
Contributor

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 refactors the ModuleWriter trait to improve its design by separating the core implementation method from convenience methods. The main method now accepts impl Read instead of byte slices, enabling streaming data processing.

  • Split ModuleWriter trait into a core trait with one method (add_data) and an extension trait (ModuleWriterExt) with convenience methods
  • Replaced byte slice parameters with impl Read to support streaming
  • Introduced StreamSha256 for calculating hashes during streaming operations
  • Simplified permission handling to binary executable/non-executable flags (0o755/0o644)

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/module_writer.rs Core refactoring: split trait into ModuleWriter and ModuleWriterExt, changed API to use impl Read, added StreamSha256 struct for streaming hash calculation, simplified permission handling
src/source_distribution.rs Updated all calls to use new add_data and add_file APIs with boolean executable parameter
src/build_context.rs Updated imports to include ModuleWriterExt and adapted method calls to new API
tests/common/metadata.rs Updated mock implementation to match new ModuleWriter trait signature
Changelog.md Added changelog entry for the refactoring

@messense messense self-requested a review November 12, 2025 06:20
@e-nomem e-nomem force-pushed the modulewriter-ext branch 2 times, most recently from 6b3ad03 to 64f8ffb Compare November 13, 2025 12:58
@e-nomem e-nomem force-pushed the modulewriter-ext branch 3 times, most recently from 006dfe4 to 5fe2cbe Compare November 19, 2025 01:57
@e-nomem
Copy link
Contributor Author

e-nomem commented Nov 19, 2025

@messense I can back out the change adding add_file_infer_permissions() so that we don't change the symlink behavior. Does the rest of the PR look good to you?

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