MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / copy_executable

Function copy_executable

crates/openshell-sandbox/src/main.rs:374–392  ·  view source on GitHub ↗

Drives `copy_self`'s file-copy logic against an arbitrary source path so tests don't depend on `current_exe()`.

(src: &Path, dest: &Path)

Source from the content-addressed store, hash-verified

372 /// Drives `copy_self`'s file-copy logic against an arbitrary source path
373 /// so tests don't depend on `current_exe()`.
374 fn copy_executable(src: &Path, dest: &Path) -> Result<()> {
375 let final_path = if dest.is_dir() {
376 dest.join(src.file_name().unwrap())
377 } else {
378 dest.to_path_buf()
379 };
380 if let Some(parent) = final_path.parent()
381 && !parent.as_os_str().is_empty()
382 {
383 std::fs::create_dir_all(parent).into_diagnostic()?;
384 }
385 std::fs::copy(src, &final_path).into_diagnostic()?;
386 let mut perms = std::fs::metadata(&final_path)
387 .into_diagnostic()?
388 .permissions();
389 perms.set_mode(0o755);
390 std::fs::set_permissions(&final_path, perms).into_diagnostic()?;
391 Ok(())
392 }
393
394 #[test]
395 fn copy_self_writes_executable_at_target_path() {

Calls 1

is_emptyMethod · 0.45