diff options
Diffstat (limited to 'src/api/mod.rs')
| -rw-r--r-- | src/api/mod.rs | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/api/mod.rs b/src/api/mod.rs index e97d94f6..ff53e6ad 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -95,11 +95,7 @@ impl EventHub { } pub fn socket_path() -> PathBuf { - if let Ok(path) = std::env::var(SOCKET_PATH_ENV_VAR) { - return PathBuf::from(path); - } - - crate::config::config_dir().join("herdr.sock") + crate::session::active_api_socket_path() } pub struct ServerHandle { @@ -1064,6 +1060,8 @@ mod tests { fn socket_path_prefers_explicit_env_override() { let _guard = env_lock().lock().unwrap(); let unique = format!("/tmp/herdr-test-{}.sock", std::process::id()); + std::env::remove_var(crate::session::SESSION_ENV_VAR); + crate::session::clear_explicit_session_for_test(); std::env::set_var(SOCKET_PATH_ENV_VAR, &unique); assert_eq!(socket_path(), PathBuf::from(&unique)); std::env::remove_var(SOCKET_PATH_ENV_VAR); @@ -1075,6 +1073,8 @@ mod tests { let config_home = unique_test_path("socket-default-config-home"); let runtime_dir = unique_test_path("socket-default-runtime"); std::env::remove_var(SOCKET_PATH_ENV_VAR); + std::env::remove_var(crate::session::SESSION_ENV_VAR); + crate::session::clear_explicit_session_for_test(); std::env::set_var("XDG_CONFIG_HOME", &config_home); std::env::set_var("XDG_RUNTIME_DIR", &runtime_dir); @@ -1088,6 +1088,26 @@ mod tests { } #[test] + fn socket_path_uses_named_session_dir() { + let _guard = env_lock().lock().unwrap(); + let config_home = unique_test_path("socket-named-config-home"); + std::env::remove_var(SOCKET_PATH_ENV_VAR); + crate::session::clear_explicit_session_for_test(); + std::env::set_var(crate::session::SESSION_ENV_VAR, "work"); + std::env::set_var("XDG_CONFIG_HOME", &config_home); + + let expected = config_home + .join(crate::config::app_dir_name()) + .join("sessions") + .join("work") + .join("herdr.sock"); + assert_eq!(socket_path(), expected); + + std::env::remove_var(crate::session::SESSION_ENV_VAR); + std::env::remove_var("XDG_CONFIG_HOME"); + } + + #[test] fn restrict_socket_permissions_sets_user_only_mode() { let dir = unique_test_path("socket-perms"); fs::create_dir_all(&dir).unwrap(); |
