(
archive: &mut tar::Builder<W>,
local_path: &Path,
archive_path: &Path,
skip_missing: bool,
)
| 630 | } |
| 631 | |
| 632 | fn append_upload_path<W: Write>( |
| 633 | archive: &mut tar::Builder<W>, |
| 634 | local_path: &Path, |
| 635 | archive_path: &Path, |
| 636 | skip_missing: bool, |
| 637 | ) -> Result<()> { |
| 638 | let metadata = match fs::symlink_metadata(local_path) { |
| 639 | Ok(metadata) => metadata, |
| 640 | Err(err) if skip_missing && err.kind() == std::io::ErrorKind::NotFound => return Ok(()), |
| 641 | Err(err) => { |
| 642 | return Err(err) |
| 643 | .into_diagnostic() |
| 644 | .wrap_err_with(|| format!("failed to stat {}", local_path.display())); |
| 645 | } |
| 646 | }; |
| 647 | let file_type = metadata.file_type(); |
| 648 | |
| 649 | if file_type.is_file() { |
| 650 | archive |
| 651 | .append_path_with_name(local_path, archive_path) |
| 652 | .into_diagnostic() |
| 653 | .wrap_err_with(|| format!("failed to add {} to tar archive", archive_path.display()))?; |
| 654 | return Ok(()); |
| 655 | } |
| 656 | |
| 657 | if file_type.is_dir() { |
| 658 | let dir_archive_path = upload_archive_dir_entry_path(archive_path); |
| 659 | archive |
| 660 | .append_dir(&dir_archive_path, local_path) |
| 661 | .into_diagnostic() |
| 662 | .wrap_err_with(|| { |
| 663 | format!( |
| 664 | "failed to add directory {} to tar archive", |
| 665 | archive_path.display() |
| 666 | ) |
| 667 | })?; |
| 668 | append_upload_dir_contents(archive, local_path, archive_path)?; |
| 669 | return Ok(()); |
| 670 | } |
| 671 | |
| 672 | if file_type.is_symlink() { |
| 673 | append_upload_symlink(archive, local_path, archive_path, &metadata)?; |
| 674 | return Ok(()); |
| 675 | } |
| 676 | |
| 677 | Err(miette::miette!( |
| 678 | "unsupported file type for upload: {}", |
| 679 | local_path.display() |
| 680 | )) |
| 681 | } |
| 682 | |
| 683 | fn upload_archive_dir_entry_path(archive_path: &Path) -> PathBuf { |
| 684 | let mut path = archive_path.as_os_str().to_os_string(); |
no test coverage detected