Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow copying File Options Again #24

Merged
merged 1 commit into from
Apr 16, 2024

Conversation

wyatt-herkamp
Copy link
Contributor

@wyatt-herkamp wyatt-herkamp commented Apr 12, 2024

When extra_data and central_extra_data were added to FileOptions we lost the ability to implement Copy for FileOptions.
Plenty of people will want to Zip a basic set of files. But now we have an unnecessary Atomic value being incremented and decremented. Also an empty allocation inside the Vec

So this solution has FileOptions take a Generic Parameter to hold "Extra Options" This can be the Unit type or ExtendedFileOptions

This also puts extra_data and central_extra_data in an Option inside ZipFileData removing the Atomic usage in some cases there too.

This does break the current code as people will need to specify the generic parameter or change FileOptions to either SimpleFileOptions or FullFileOptions

I also corrected the write_dir test to remove the deprecated API calls

Copy link
Member

@Pr0methean Pr0methean left a comment

Choose a reason for hiding this comment

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

Mostly looks good, but I have some nitpicks.

Cargo.toml Show resolved Hide resolved
examples/write_dir.rs Outdated Show resolved Hide resolved
examples/write_dir.rs Show resolved Hide resolved
examples/write_sample.rs Outdated Show resolved Hide resolved
src/read.rs Show resolved Hide resolved
@wyatt-herkamp wyatt-herkamp force-pushed the allow_copy_file_options branch from 51739f5 to 16f9e53 Compare April 14, 2024 20:39
Copy link
Member

@Pr0methean Pr0methean left a comment

Choose a reason for hiding this comment

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

Almost perfect! I prefer methods to return a borrow rather than a clone, so that the caller can decide whether to clone it.

src/types.rs Outdated Show resolved Hide resolved
src/write.rs Outdated Show resolved Hide resolved
@Pr0methean
Copy link
Member

Pr0methean commented Apr 14, 2024

The build currently fails; could you please fix it? You may need to build with --all-features and with --no-default-features to reproduce the errors.

Also, this PR raises a Clippy error:

error: using `clone` on type `FileOptions<()>` which implements the `Copy` trait
Error:    --> examples/write_dir.rs:106:47
    |
106 |             zip.add_directory(path_as_string, options.clone())?;
    |                                               ^^^^^^^^^^^^^^^ help: try removing the `clone` call: `options`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy
    = note: `-D clippy::clone-on-copy` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::clone_on_copy)]`

src/write.rs Outdated

trait Sealed {}
/// File options Extensions
#[allow(private_bounds)]
Copy link
Member

Choose a reason for hiding this comment

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

Please add #[allow(unknown_lints)] as well, since this lint didn't exist in 1.70 (the current MSRV).

@Pr0methean
Copy link
Member

Pr0methean commented Apr 15, 2024

Hi,

It turns out that having a public trait extend a private trait was actually an error until Rust 1.74 (rust-lang/rust#113126, https://doc.rust-lang.org/error_codes/E0445.html) which has only been stable since November. Is there another way you can implement the sealing so that we don't have to bump the MSRV that far?

src/write.rs Outdated
#[allow(unknown_lints)]
#[allow(private_bounds)]
#[doc(hidden)]
pub trait FileOptionExtension: Default + Sealed {
Copy link
Member

Choose a reason for hiding this comment

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

This turns out not to be allowed before 1.74.0, and the current MSRV is 1.70.0. To fix this, make Sealed a public member of a private module; see https://predr.ag/blog/definitive-guide-to-sealed-traits-in-rust/#sealing-traits-with-a-supertrait and https://doc.rust-lang.org/error_codes/E0445.html#.

@wyatt-herkamp
Copy link
Contributor Author

Hi,

It turns out that having a public trait extend a private trait was actually an error until Rust 1.74 (rust-lang/rust#113126, doc.rust-lang.org/error_codes/E0445.html) which has only been stable since November. Is there another way you can implement the sealing so that we don't have to bump the MSRV that far?

I think this works

@Pr0methean Pr0methean enabled auto-merge April 15, 2024 19:55
@Pr0methean
Copy link
Member

Thanks; this will be merged automatically provided the tests pass.

@Pr0methean
Copy link
Member

Pr0methean commented Apr 15, 2024

Whoops, looks like some of your commits aren't signed! I'd suggest squashing the PR so that you only have to sign one.

@wyatt-herkamp
Copy link
Contributor Author

Please stop merging every commit into my PR.

A. I rather use Rebase
B. That was a completely irrelevant file that does not require merging.

If you are not doing that. Then what is Github doing? I have never had a PR auto-merge commits like this.

auto-merge was automatically disabled April 15, 2024 20:24

Head branch was pushed to by a user without write access

@wyatt-herkamp wyatt-herkamp force-pushed the allow_copy_file_options branch from e297804 to 6ff56b5 Compare April 15, 2024 20:24
@Pr0methean
Copy link
Member

After your squash and force-push, I'm still seeing:

"Merging is blocked
The base branch requires all commits to be signed. Learn more about signing commits."

This indicates that GitHub still doesn't recognize your signature. When it's recognized, you'll be able to see a Verified badge on the commit on the source branch's page.

@wyatt-herkamp wyatt-herkamp force-pushed the allow_copy_file_options branch from 6ff56b5 to 61afe4d Compare April 15, 2024 20:32
@Pr0methean Pr0methean enabled auto-merge April 15, 2024 20:33
@Pr0methean
Copy link
Member

Pr0methean commented Apr 15, 2024

This repo's main branch has the "Require branches to be up to date before merging" rule, to prevent merging two PRs that were compatible with their last common ancestor but not with each other (e.g. because they add different new functions with the same name).

@wyatt-herkamp
Copy link
Contributor Author

wyatt-herkamp commented Apr 15, 2024

After your squash and force-push, I'm still seeing:

Yeah I had done it in two separate actions. I have never setup Git Signing before. So It took me a moment.

auto-merge was automatically disabled April 15, 2024 20:40

Pull request was closed

@wyatt-herkamp wyatt-herkamp reopened this Apr 15, 2024
@Pr0methean Pr0methean enabled auto-merge April 15, 2024 20:40
@Pr0methean
Copy link
Member

Pr0methean commented Apr 15, 2024

Please don't close and reopen the PR unless you've rebased it, because then the CI checks are ignored and I have to manually approve them to start again. (If you've rebased it, then it's fine, because I'd have to restart them anyway.)

@Pr0methean
Copy link
Member

Pr0methean commented Apr 15, 2024

It looks like displaying a "Rebase branch" button instead of "Update branch" is in a lot of people's wish lists: https://github.com/orgs/community/discussions/3245 In future, I'll try to remember to check whether rebasing is an option; but it may not be if it would invalidate your signatures. (You'd think that if that happened, GitHub would be able to replace the signatures with ones of its own; not sure why that isn't implemented.)

@wyatt-herkamp
Copy link
Contributor Author

It looks like displaying a "Rebase branch" button instead of "Update branch" is in a lot of people's wish lists: https://github.com/orgs/community/discussions/3245 In future, I'll try to remember to check whether rebasing is an option; but it may not be if it would invalidate your signatures. (You'd think that if that happened, GitHub would be able to replace the signatures with ones of its own; not sure why that isn't implemented.)

I just wish it would block it. Let me handle the merge or rebase. Don't do it automatically.

@Pr0methean
Copy link
Member

Pr0methean commented Apr 15, 2024

That means the CI can't run until you've rebased and I've approved the rebase to have the CI run on it, so PRs would take even longer to be merged. Plus, I may not be able to check PRs daily in the future -- I'm currently on leave from work, but will be either returning to full-time work or searching for a new job starting in early May, which may cause further delays. This is especially true if https://github.com/orgs/community/discussions/119719 and https://github.com/orgs/community/discussions/119723 turn out not to be the last issues of their kind that I'll get temporarily stuck on, or if #26 and #27 aren't the last config changes I'll discover a need for while others' PRs are waiting on CI. I'm fairly new at receiving PRs from other humans on a repo in parallel with each other and with my own work on the same repo, so there may be a lot of gotchas I've yet to discover. Please continue to be patient.

@Pr0methean Pr0methean disabled auto-merge April 16, 2024 00:12
@Pr0methean Pr0methean merged commit 66e0b82 into zip-rs:master Apr 16, 2024
18 of 33 checks passed
@Pr0methean
Copy link
Member

Thanks! This is now merged, and I expect to release it in version 1.1.0 within the next few days.

@wyatt-herkamp wyatt-herkamp deleted the allow_copy_file_options branch April 16, 2024 00:25
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