Skip to content

Commit

Permalink
added binary execution permission check for Linux and macOS
Browse files Browse the repository at this point in the history
Added check if the binary file has execution permissions on Linux and macOS. Using #[cfg(unix)] to conditionally include the code for Unix-based systems. If the binary does not have execution permissions, it attempts to change the permissions to allow execution using the set_mode() function from std::os::unix::fs::PermissionsExt and fs::set_permissions() from the std::fs module.
  • Loading branch information
1zun4 committed Jul 17, 2023
1 parent 9037d60 commit 4d1ef3d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src-tauri/src/minecraft/java/jre_downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ pub async fn find_java_binary(runtimes_folder: &Path, jre_version: u32) -> Resul
};

if java_binary.exists() {
// Check if the binary has execution permissions on linux and macOS
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;

let metadata = fs::metadata(&java_binary).await?;

if !metadata.permissions().mode() & 0o111 != 0 {
// try to change permissions
let mut permissions = metadata.permissions();
permissions.set_mode(0o111);
fs::set_permissions(&java_binary, permissions).await?;
}
}

return Ok(java_binary.absolutize()?.to_path_buf());
}
}
Expand Down

0 comments on commit 4d1ef3d

Please sign in to comment.