From 274898adffae37bba88df32e25b1aae1d10d7399 Mon Sep 17 00:00:00 2001 From: Marcel Sery Date: Wed, 10 Jul 2019 09:29:54 +0200 Subject: [PATCH] Automatic setting of executable mode on executed file --- warp-runner/src/executor.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/warp-runner/src/executor.rs b/warp-runner/src/executor.rs index 270b1b7..435f465 100644 --- a/warp-runner/src/executor.rs +++ b/warp-runner/src/executor.rs @@ -1,5 +1,11 @@ use std::env; use std::io; +#[cfg(target_family = "unix")] +use std::fs; +#[cfg(target_family = "unix")] +use std::fs::Permissions; +#[cfg(target_family = "unix")] +use std::os::unix::fs::PermissionsExt; use std::path::Path; use std::process::Command; use std::process::Stdio; @@ -13,8 +19,16 @@ pub fn execute(target: &Path) -> io::Result { do_execute(target, &args) } +#[cfg(target_family = "unix")] +fn ensure_executable(target: &Path) { + let perms = Permissions::from_mode(0o770); + fs::set_permissions(target, perms).unwrap(); +} + #[cfg(target_family = "unix")] fn do_execute(target: &Path, args: &[String]) -> io::Result { + ensure_executable(target); + Ok(Command::new(target) .args(args) .stdin(Stdio::inherit())