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

fix: add tolerant tar extraction on windows to solve failing on symlinks #1138

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Krande
Copy link

@Krande Krande commented Oct 26, 2024

Hey guys,

this is supposed to close #940.

This is my first time writing rust beyond just "hello world", so any suggestions for improvements are most welcome!

@wolfv
Copy link
Member

wolfv commented Oct 26, 2024

Thank you! On first glance, looks good!

@Krande
Copy link
Author

Krande commented Oct 28, 2024

@wolfv i think I've fixed the linting issue. Let me know if there is anything else I should consider.

Copy link
Member

@wolfv wolfv left a comment

Choose a reason for hiding this comment

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

Hi! Excellent PR and I agree about being more lenient about symlinks on Windows.

I think the error handling is a bit too lenient now, though. There are definitely errors that are worth bailing out.

match file.header().entry_type() {
EntryType::Symlink if cfg!(target_os = "windows") => {
if let Err(e) = file.unpack(&path) {
println!(
Copy link
Member

Choose a reason for hiding this comment

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

We should always use tracing::warn! or tracing::error!.

}
}
Err(e) => {
println!("Warning: failed to read an entry due to {:?}", e);
Copy link
Member

Choose a reason for hiding this comment

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

I think in this case, we should also return the error and fail the operation.

}
_ => {
if let Err(e) = file.unpack(&path) {
println!("Warning: failed to unpack {:?} due to {:?}", path, e);
Copy link
Member

Choose a reason for hiding this comment

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

Again we should return the error here :)

@wolfv
Copy link
Member

wolfv commented Oct 29, 2024

Hi @Krande - let me know if you want to make the changes or if you would prefer me taking over :)

@Krande
Copy link
Author

Krande commented Oct 29, 2024

If you have time to implement the changes, feel free to finish them:) if not, I'll likely start to implement them after lunch time tomorrow!

@wolfv
Copy link
Member

wolfv commented Oct 29, 2024

I looked a little bit deeper and I think unfortunately this doesn't cover a bunch of (other) edge cases that the original tar extraction code covers. That's really unfortunate. Ideally we could implement this kind of behavior / filtering in tar-rs directly.

@Krande
Copy link
Author

Krande commented Oct 30, 2024

I see. I checked tar-rs and found this alexcrichton/tar-rs#280 which I guess is related.

@Krande
Copy link
Author

Krande commented Oct 30, 2024

Would it be possible to make this tolerant extraction feature optional by hiding it behind an opt-in flag until a better long-term solution can be found?

That way, it is at least possible for us forced to use windows in our day jobs to use rattler-build for projects containing symlinks :)

@wolfv
Copy link
Member

wolfv commented Nov 17, 2024

A "shitty" workaround is to keep the source as tarball. This is possible since the last release or two by adding a option:

file_name: source.tar.gz

Then you can add e.g. 7zip to your build dependencies, and extract the source code during the build step.

Is that an OKish workaround? Sorry for not coming up with something better. I would love an option in the tar crate. Maybe you could also work on a PR over there?

@Krande
Copy link
Author

Krande commented Nov 17, 2024

Is that an OKish workaround?

Yeah, anything that works is fine for now :) That at least gives me a chance at using rattler-build for more packages :)

Maybe you could also work on a PR over there?

Sure, I can try. It would also help if you can shed some light on the types of edge cases a filtering behaviour in tar-rs should be able to cover? Referring to your comment

I looked a little bit deeper and I think unfortunately this doesn't cover a bunch of (other) edge cases that the original tar extraction code covers.

@wolfv
Copy link
Member

wolfv commented Nov 17, 2024

@Krande I think if you add this behavior to the original tar, then we can keep using the existing unextract functionality that covers all the edge cases. But we can just gracefully warn instead of fail when we cannot create a symlink.

You could add a SymlinkBehavior enum to tar-rs and have Fail, Warn or Copy options and then implement them accordingly when symlinking fails.

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.

Failed to extract archive on windows
2 participants