From 199305c41341b5540674e91317856bf64c086e79 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Wed, 15 Jun 2022 00:06:07 +0200 Subject: [PATCH] Fix reflink sometimes removing executable bit Or, well, work around it. --- nih_plug_xtask/src/lib.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/nih_plug_xtask/src/lib.rs b/nih_plug_xtask/src/lib.rs index 9980441d..8cdbc2bb 100644 --- a/nih_plug_xtask/src/lib.rs +++ b/nih_plug_xtask/src/lib.rs @@ -5,6 +5,9 @@ use std::fs; use std::path::{Path, PathBuf}; use std::process::Command; +#[cfg(unix)] +use std::os::unix::fs::PermissionsExt; + mod symbols; /// Re-export for the main function. @@ -232,6 +235,22 @@ fn bundle_binary( reflink::reflink_or_copy(&bin_path, &standalone_binary_path) .context("Could not copy binary to standalone bundle")?; + // FIXME: The reflink crate seems to sometime strip away the executable bit, so we need to help + // it a little here + #[cfg(unix)] + if let Ok(metadata) = fs::metadata(&standalone_binary_path) { + // These are the executable bits + let mut permissions = metadata.permissions(); + permissions.set_mode(permissions.mode() | 0b0001001001); + + fs::set_permissions(&standalone_binary_path, permissions).with_context(|| { + format!( + "Could not make '{}' executable", + standalone_binary_path.display() + ) + })?; + } + let standalone_bundle_home = Path::new(BUNDLE_HOME).join( Path::new(&standalone_bundle_binary_name) .components()