Automatic setting of executable mode on executed file

This commit is contained in:
Marcel Sery 2019-07-10 09:29:54 +02:00
parent 6c49fad2fa
commit 274898adff

View File

@ -1,5 +1,11 @@
use std::env; use std::env;
use std::io; 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::path::Path;
use std::process::Command; use std::process::Command;
use std::process::Stdio; use std::process::Stdio;
@ -13,8 +19,16 @@ pub fn execute(target: &Path) -> io::Result<i32> {
do_execute(target, &args) 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")] #[cfg(target_family = "unix")]
fn do_execute(target: &Path, args: &[String]) -> io::Result<i32> { fn do_execute(target: &Path, args: &[String]) -> io::Result<i32> {
ensure_executable(target);
Ok(Command::new(target) Ok(Command::new(target)
.args(args) .args(args)
.stdin(Stdio::inherit()) .stdin(Stdio::inherit())