From e2267aba12aa44603047aeaced00d2f7306645fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=A4kil=C3=A4?= <68429681+maekilae@users.noreply.github.com> Date: Fri, 6 Feb 2026 16:34:36 +0100 Subject: [PATCH] Fix text_threads_dir() non-compliance with XDG spec (#45771) Closes #41373 Release Notes: - Ensures that XDG specs are followed on MacOS and Linux with backwards compatibility. Changes -Added ```state_dir``` to get XDG_STATE_HOME on macos and linux, no change to windows. -Changed ```text_threads_dir``` to a fallback, ```text_threads_dir_fallback``` -Re-implemented ```text_threads_dir``` to use ```state_dir``` --------- Co-authored-by: AdamJedl <100023363+AdamJedl@users.noreply.github.com> --- crates/paths/src/paths.rs | 41 +++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/crates/paths/src/paths.rs b/crates/paths/src/paths.rs index 02275d8cbd26ab86435476c5adeaf81ec09a29e9..656188e249fc864e1328c8f458bdc46aa7eaea3a 100644 --- a/crates/paths/src/paths.rs +++ b/crates/paths/src/paths.rs @@ -122,6 +122,29 @@ pub fn data_dir() -> &'static PathBuf { }) } +pub fn state_dir() -> &'static PathBuf { + static STATE_DIR: OnceLock = OnceLock::new(); + STATE_DIR.get_or_init(|| { + if cfg!(target_os = "macos") { + return home_dir().join(".local").join("state").join("Zed"); + } + + if cfg!(any(target_os = "linux", target_os = "freebsd")) { + return if let Ok(flatpak_xdg_state) = std::env::var("FLATPAK_XDG_STATE_HOME") { + flatpak_xdg_state.into() + } else { + dirs::state_dir().expect("failed to determine XDG_STATE_HOME directory") + } + .join("zed"); + } else { + // Windows + return dirs::data_local_dir() + .expect("failed to determine LocalAppData directory") + .join("Zed"); + } + }) +} + /// Returns the path to the temp directory used by Zed. pub fn temp_dir() -> &'static PathBuf { static TEMP_DIR: OnceLock = OnceLock::new(); @@ -287,10 +310,9 @@ pub fn snippets_dir() -> &'static PathBuf { SNIPPETS_DIR.get_or_init(|| config_dir().join("snippets")) } -/// Returns the path to the contexts directory. -/// -/// This is where the saved contexts from the Assistant are stored. -pub fn text_threads_dir() -> &'static PathBuf { +// Returns old path to contexts directory. +// Fallback +fn text_threads_dir_fallback() -> &'static PathBuf { static CONTEXTS_DIR: OnceLock = OnceLock::new(); CONTEXTS_DIR.get_or_init(|| { if cfg!(target_os = "macos") { @@ -300,6 +322,17 @@ pub fn text_threads_dir() -> &'static PathBuf { } }) } +/// Returns the path to the contexts directory. +/// +/// This is where the saved contexts from the Assistant are stored. +pub fn text_threads_dir() -> &'static PathBuf { + let fallback_dir = text_threads_dir_fallback(); + if fallback_dir.exists() { + return fallback_dir; + } + static CONTEXTS_DIR: OnceLock = OnceLock::new(); + CONTEXTS_DIR.get_or_init(|| state_dir().join("conversations")) +} /// Returns the path to the contexts directory. ///