Automatic setting of executable mode on executed file
This commit is contained in:
parent
6c49fad2fa
commit
274898adff
@ -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<i32> {
|
||||
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<i32> {
|
||||
ensure_executable(target);
|
||||
|
||||
Ok(Command::new(target)
|
||||
.args(args)
|
||||
.stdin(Stdio::inherit())
|
||||
|
Loading…
Reference in New Issue
Block a user