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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions src/source/extract.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Helpers to extract archives
use std::{ffi::OsStr, io::BufRead, path::Path};

use crate::console_utils::LoggingOutputHandler;
use std::{ffi::OsStr, io::BufRead, path::Path};
use tar::EntryType;

use fs_err as fs;
use fs_err::File;
Expand Down Expand Up @@ -136,9 +136,38 @@ pub(crate) fn extract_tar(
));

let tmp_extraction_dir = tempfile::Builder::new().tempdir_in(target_directory)?;
archive
.unpack(&tmp_extraction_dir)
.map_err(|e| SourceError::TarExtractionError(e.to_string()))?;
for entry in archive.entries()? {
match entry {
Ok(mut file) => {
let path = tmp_extraction_dir.path().join(file.path()?);

// Ensure all intermediate directories exist before unpacking
if let Some(parent) = path.parent() {
fs::create_dir_all(parent)?;
}

// Attempt to unpack symlinks and regular files, logging any issues
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!.

"Warning: failed to extract symlink {:?} due to {:?}",
path, e
);
}
}
_ => {
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 :)

}
}
}
}
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.

}
}
}

move_extracted_dir(tmp_extraction_dir.path(), target_directory)?;
progress_bar.finish_with_message("Extracted...");
Expand Down
Loading