Automatic setting of executable mode on executed file
As proposed by @marcellus-trixus in https://github.com/dgiagio/warp/issues/23#issuecomment-509946967
This commit is contained in:
parent
7815d0319b
commit
b82c90beb3
@ -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