From 06e4c73f4e967327e408ed75d51b709793b0f63c Mon Sep 17 00:00:00 2001 From: Pavel Zwerschke Date: Thu, 28 Nov 2024 10:13:34 +0100 Subject: [PATCH] use \r\n for windows executable --- src/pack.rs | 15 +++++++++++---- ...ntegration_test__sha256-win-64-executable.snap | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/pack.rs b/src/pack.rs index bf3ff44..5a79bea 100644 --- a/src/pack.rs +++ b/src/pack.rs @@ -340,6 +340,12 @@ async fn create_self_extracting_executable( target: &Path, platform: Platform, ) -> Result<()> { + let line_ending = if platform.is_windows() { + b"\r\n".to_vec() + } else { + b"\n".to_vec() + }; + let archive = Builder::new(Vec::new()); let compressor = write_archive(archive, input_dir).await?; @@ -410,7 +416,7 @@ async fn create_self_extracting_executable( .map_err(|e| anyhow!("could not create final executable file: {}", e))?; final_executable.write_all(header.as_bytes()).await?; - final_executable.write_all(b"\n").await?; // Add a newline after the header + final_executable.write_all(&line_ending).await?; // Add a newline after the header // Encode the archive to base64 let archive_base64 = STANDARD.encode(&compressor); @@ -418,12 +424,13 @@ async fn create_self_extracting_executable( .write_all(archive_base64.as_bytes()) .await?; - final_executable.write_all(b"\n").await?; + final_executable.write_all(&line_ending).await?; if platform.is_windows() { - final_executable.write_all(b"__END_ARCHIVE__\n").await?; + final_executable.write_all(b"__END_ARCHIVE__").await?; } else { - final_executable.write_all(b"@@END_ARCHIVE@@\n").await?; + final_executable.write_all(b"@@END_ARCHIVE@@").await?; } + final_executable.write_all(&line_ending).await?; // Encode the executable to base64 let executable_base64 = STANDARD.encode(&executable_bytes); diff --git a/tests/snapshots/integration_test__sha256-win-64-executable.snap b/tests/snapshots/integration_test__sha256-win-64-executable.snap index 117c239..4753e8a 100644 --- a/tests/snapshots/integration_test__sha256-win-64-executable.snap +++ b/tests/snapshots/integration_test__sha256-win-64-executable.snap @@ -1,7 +1,7 @@ --- source: tests/integration_test.rs -assertion_line: 358 +assertion_line: 366 expression: "&sha256_digest" snapshot_kind: text --- -7D564558F9576FACF4BF9188CCE0B2F8BD98C5E52A8456DE4F06378BEF11BE27 +D651688B08263EA415C95AF1298D337088953CD260BFFC1AB287D75E2F467D2A