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

Function with_tmp_xdg

crates/openshell-bootstrap/src/edge_token.rs:94–109  ·  view source on GitHub ↗
(tmp: &std::path::Path, f: F)

Source from the content-addressed store, hash-verified

92 /// tempdir, run `f`, then restore the original value.
93 #[allow(unsafe_code)]
94 fn with_tmp_xdg<F: FnOnce()>(tmp: &std::path::Path, f: F) {
95 let _guard = crate::XDG_TEST_LOCK
96 .lock()
97 .unwrap_or_else(std::sync::PoisonError::into_inner);
98 let orig = std::env::var("XDG_CONFIG_HOME").ok();
99 unsafe {
100 std::env::set_var("XDG_CONFIG_HOME", tmp);
101 }
102 f();
103 unsafe {
104 match orig {
105 Some(v) => std::env::set_var("XDG_CONFIG_HOME", v),
106 None => std::env::remove_var("XDG_CONFIG_HOME"),
107 }
108 }
109 }
110
111 #[test]
112 fn store_and_load_edge_token_roundtrip() {

Calls

no outgoing calls