MCPcopy Create free account
hub / github.com/NVIDIA/NemoClaw / write_executable

Function write_executable

crates/test-support/executable.rs:20–39  ·  view source on GitHub ↗

Create `path` with `contents` and mode 0700.

(path: &Path, contents: impl AsRef<[u8]>)

Source from the content-addressed store, hash-verified

18
19/// Create `path` with `contents` and mode 0700.
20pub fn write_executable(path: &Path, contents: impl AsRef<[u8]>) {
21 let mut writer = Command::new("/bin/sh")
22 .args(["-c", "umask 077 && cat > \"$1\" && chmod 700 \"$1\"", "sh"])
23 .arg(path)
24 .stdin(Stdio::piped())
25 .spawn()
26 .expect("cannot start /bin/sh to write a test executable");
27 writer
28 .stdin
29 .take()
30 .expect("piped stdin")
31 .write_all(contents.as_ref())
32 .expect("cannot send a test executable to /bin/sh");
33 let status = writer.wait().expect("cannot wait for /bin/sh");
34 assert!(
35 status.success(),
36 "cannot write {}: {status}",
37 path.display()
38 );
39}

Calls 3

stdinMethod · 0.80
takeMethod · 0.80
waitMethod · 0.45

Tested by 3

newMethod · 0.68
oshFunction · 0.68
write_scriptFunction · 0.68