Skip to content
Merged
Show file tree
Hide file tree
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
48 changes: 48 additions & 0 deletions src/commands/build/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ fn upload_file(
mod tests {
use super::*;
use std::fs;
use std::os::unix::fs::symlink;
use zip::ZipArchive;

#[test]
Expand Down Expand Up @@ -651,4 +652,51 @@ mod tests {
);
Ok(())
}

#[test]
fn test_normalize_directory_preserves_symlinks() -> Result<()> {
let temp_dir = crate::utils::fs::TempDir::create()?;
let test_dir = temp_dir.path().join("TestApp.xcarchive");
fs::create_dir_all(test_dir.join("Products"))?;

// Create a regular file
fs::write(test_dir.join("Products").join("app.txt"), "test content")?;

// Create a symlink pointing to the regular file
let symlink_path = test_dir.join("Products").join("app_link.txt");
symlink("app.txt", &symlink_path)?;

let result_zip = normalize_directory(&test_dir, temp_dir.path())?;
let zip_file = fs::File::open(result_zip.path())?;
let mut archive = ZipArchive::new(zip_file)?;

// Check that both the regular file and symlink are in the zip
let mut has_regular_file = false;
let mut has_symlink = false;

for i in 0..archive.len() {
let file = archive.by_index(i)?;
let file_name = file.name();

if file_name == "TestApp.xcarchive/Products/app.txt" {
has_regular_file = true;
// Verify it's actually a regular file, not a symlink
assert!(
!file.is_symlink(),
"app.txt should be a regular file, not a symlink"
);
} else if file_name == "TestApp.xcarchive/Products/app_link.txt" {
has_symlink = true;
// Verify it's actually a symlink
assert!(
file.is_symlink(),
"app_link.txt should be a symlink in the zip"
);
}
}

assert!(has_regular_file, "Regular file should be in zip");
assert!(has_symlink, "Symlink should be preserved in zip");
Ok(())
}
}
25 changes: 20 additions & 5 deletions src/utils/build/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ use zip::{DateTime, ZipWriter};

fn sort_entries(path: &Path) -> Result<impl Iterator<Item = (PathBuf, PathBuf)>> {
Ok(WalkDir::new(path)
.follow_links(true)
.into_iter()
.filter_map(Result::ok)
.filter(|entry| entry.path().is_file())
.filter(|entry| {
let path = entry.path();
// Include both regular files and symlinks
path.is_file() || path.is_symlink()
})
.map(|entry| {
let entry_path = entry.into_path();
let relative_path = entry_path.strip_prefix(path)?.to_owned();
Expand Down Expand Up @@ -52,16 +55,28 @@ fn add_entries_to_zip(

let zip_path = format!("{directory_name}/{}", relative_path.to_string_lossy());

zip.start_file(zip_path, options)?;
let file_byteview = ByteView::open(&entry_path)?;
zip.write_all(file_byteview.as_slice())?;
if entry_path.is_symlink() {
// Handle symlinks by reading the target path and writing it as a symlink
let target = std::fs::read_link(&entry_path)?;
let target_str = target.to_string_lossy();

// Create a symlink entry in the zip
zip.add_symlink(zip_path, &target_str, options)?;
Comment thread
noahsmartin marked this conversation as resolved.
} else {
// Handle regular files
zip.start_file(zip_path, options)?;
let file_byteview = ByteView::open(&entry_path)?;
zip.write_all(file_byteview.as_slice())?;
}
file_count += 1;
}

Ok(file_count)
}

// For XCArchive directories, we'll zip the entire directory
// It's important to not change the contents of the directory or the size
// analysis will be wrong and the code signature will break.
pub fn normalize_directory(path: &Path, parsed_assets_path: &Path) -> Result<TempFile> {
debug!("Creating normalized zip for directory: {}", path.display());

Expand Down