Skip to content

Commit

Permalink
Add permission for the executable on unix along with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
prsabahrami committed Nov 27, 2024
1 parent 71058b6 commit 1151f6a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
8 changes: 8 additions & 0 deletions src/pack.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
collections::{HashMap, HashSet},
fs::FileTimes,
os::unix::fs::PermissionsExt as _,
path::{Path, PathBuf},
sync::Arc,
};
Expand Down Expand Up @@ -456,6 +457,13 @@ async fn create_self_extracting_executable(
.write_all(executable_base64.as_bytes())
.await?;

// Make the executable executable
if !platform.is_windows() {
let mut perms = final_executable.metadata().await?.permissions();
perms.set_mode(0o755);
final_executable.set_permissions(perms).await?;
}

Ok(())
}

Expand Down
31 changes: 19 additions & 12 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,20 @@ async fn test_run_packed_executable(options: Options, required_fs_objects: Vec<&

let pixi_pack_bits = &pack_file_contents[archive_end + "__END_ARCHIVE__".len()..];
assert!(!pixi_pack_bits.is_empty());

assert_eq!(pack_file.extension().unwrap(), "ps1");
let output = Command::new("powershell")
.arg("-File")
.arg(&pack_file)
.arg("-o")
.arg(options.output_dir.path())
.output()
.expect("Failed to execute packed file for extraction");
assert!(
output.status.success(),
"Packed file execution failed: {:?}",
output
);
}
#[cfg(not(target_os = "windows"))]
{
Expand All @@ -464,13 +478,10 @@ async fn test_run_packed_executable(options: Options, required_fs_objects: Vec<&

let pixi_pack_bits = &pack_file_contents[archive_end + "@@END_ARCHIVE@@".len()..];
assert!(!pixi_pack_bits.is_empty());
}

#[cfg(target_os = "windows")]
{
assert_eq!(pack_file.extension().unwrap(), "ps1");
let output = Command::new("powershell")
.arg("-File")
assert_eq!(pack_file.extension().unwrap(), "sh");

let output = Command::new("bash")
.arg(&pack_file)
.arg("-o")
.arg(options.output_dir.path())
Expand All @@ -481,12 +492,8 @@ async fn test_run_packed_executable(options: Options, required_fs_objects: Vec<&
"Packed file execution failed: {:?}",
output
);
}
#[cfg(not(target_os = "windows"))]
{
assert_eq!(pack_file.extension().unwrap(), "sh");
let output = Command::new("bash")
.arg(&pack_file)

let output = Command::new(&pack_file)
.arg("-o")
.arg(options.output_dir.path())
.output()
Expand Down

0 comments on commit 1151f6a

Please sign in to comment.