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

Function with_tmp_xdg_and_system

crates/openshell-bootstrap/src/metadata.rs:592–613  ·  view source on GitHub ↗
(user: &Path, system: &Path, f: F)

Source from the content-addressed store, hash-verified

590 /// run `f`, then restore both env vars.
591 #[allow(unsafe_code)]
592 fn with_tmp_xdg_and_system<F: FnOnce()>(user: &Path, system: &Path, f: F) {
593 let _guard = crate::XDG_TEST_LOCK
594 .lock()
595 .unwrap_or_else(std::sync::PoisonError::into_inner);
596 let orig_xdg = std::env::var("XDG_CONFIG_HOME").ok();
597 let orig_sys = std::env::var(crate::paths::SYSTEM_GATEWAY_DIR_ENV).ok();
598 unsafe {
599 std::env::set_var("XDG_CONFIG_HOME", user);
600 std::env::set_var(crate::paths::SYSTEM_GATEWAY_DIR_ENV, system);
601 }
602 f();
603 unsafe {
604 match orig_xdg {
605 Some(v) => std::env::set_var("XDG_CONFIG_HOME", v),
606 None => std::env::remove_var("XDG_CONFIG_HOME"),
607 }
608 match orig_sys {
609 Some(v) => std::env::set_var(crate::paths::SYSTEM_GATEWAY_DIR_ENV, v),
610 None => std::env::remove_var(crate::paths::SYSTEM_GATEWAY_DIR_ENV),
611 }
612 }
613 }
614
615 /// Write a `<gateways-dir>/<name>/metadata.json` file for the given endpoint.
616 fn write_system_metadata(dir: &Path, name: &str, endpoint: &str) {

Calls

no outgoing calls