Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
XDG_BASE_DIR support (linux, windows) (#10808)
ElKowarb29643168c32
diff --git a/crates/util/src/paths.rs b/crates/util/src/paths.rsindex 97740fb75c8..205ea72f0af 100644--- a/crates/util/src/paths.rs+++ b/crates/util/src/paths.rs@@ -12,49 +12,54 @@ lazy_static::lazy_static! {dirs::config_dir().expect("failed to determine RoamingAppData directory").join("Zed")+ } else if cfg!(target_os = "linux") {+ dirs::config_dir()+ .expect("failed to determine XDG_CONFIG_HOME directory")+ .join("zed")} else {HOME.join(".config").join("zed")};- pub static ref CONVERSATIONS_DIR: PathBuf = CONFIG_DIR.join("conversations");- pub static ref EMBEDDINGS_DIR: PathBuf = CONFIG_DIR.join("embeddings");- pub static ref THEMES_DIR: PathBuf = CONFIG_DIR.join("themes");- pub static ref LOGS_DIR: PathBuf = if cfg!(target_os = "macos") {- HOME.join("Library/Logs/Zed")- } else if cfg!(target_os = "windows") {- dirs::data_local_dir()- .expect("failed to determine LocalAppData directory")- .join("Zed/logs")+ pub static ref CONVERSATIONS_DIR: PathBuf = if cfg!(target_os = "macos") {+ CONFIG_DIR.join("conversations")} else {- CONFIG_DIR.join("logs")+ SUPPORT_DIR.join("conversations")};+ pub static ref EMBEDDINGS_DIR: PathBuf = if cfg!(target_os = "macos") {+ CONFIG_DIR.join("embeddings")+ } else {+ SUPPORT_DIR.join("embeddings")+ };+ pub static ref THEMES_DIR: PathBuf = CONFIG_DIR.join("themes");+pub static ref SUPPORT_DIR: PathBuf = if cfg!(target_os = "macos") {HOME.join("Library/Application Support/Zed")+ } else if cfg!(target_os = "linux") {+ dirs::data_local_dir()+ .expect("failed to determine XDG_DATA_DIR directory")+ .join("zed")} else if cfg!(target_os = "windows") {- dirs::config_dir()- .expect("failed to determine RoamingAppData directory")+ dirs::data_local_dir()+ .expect("failed to determine LocalAppData directory").join("Zed")} else {CONFIG_DIR.clone()};+ pub static ref LOGS_DIR: PathBuf = if cfg!(target_os = "macos") {+ HOME.join("Library/Logs/Zed")+ } else {+ SUPPORT_DIR.join("logs")+ };pub static ref EXTENSIONS_DIR: PathBuf = SUPPORT_DIR.join("extensions");pub static ref LANGUAGES_DIR: PathBuf = SUPPORT_DIR.join("languages");pub static ref COPILOT_DIR: PathBuf = SUPPORT_DIR.join("copilot");pub static ref DEFAULT_PRETTIER_DIR: PathBuf = SUPPORT_DIR.join("prettier");pub static ref DB_DIR: PathBuf = SUPPORT_DIR.join("db");- pub static ref CRASHES_DIR: PathBuf = if cfg!(target_os = "macos") {- HOME.join("Library/Logs/DiagnosticReports")- } else if cfg!(target_os = "windows") {- dirs::data_local_dir()- .expect("failed to determine LocalAppData directory")- .join("Zed/crashes")- } else {- CONFIG_DIR.join("crashes")- };- pub static ref CRASHES_RETIRED_DIR: PathBuf = if cfg!(target_os = "macos") {- HOME.join("Library/Logs/DiagnosticReports/Retired")- } else {- CRASHES_DIR.join("retired")- };+ pub static ref CRASHES_DIR: Option<PathBuf> = cfg!(target_os = "macos")+ .then_some(HOME.join("Library/Logs/DiagnosticReports"));+ pub static ref CRASHES_RETIRED_DIR: Option<PathBuf> = CRASHES_DIR+ .as_ref()+ .map(|dir| dir.join("Retired"));+pub static ref SETTINGS: PathBuf = CONFIG_DIR.join("settings.json");pub static ref KEYMAP: PathBuf = CONFIG_DIR.join("keymap.json");pub static ref TASKS: PathBuf = CONFIG_DIR.join("tasks.json");@@ -65,9 +70,13 @@ lazy_static::lazy_static! {pub static ref LOCAL_TASKS_RELATIVE_PATH: &'static Path = Path::new(".zed/tasks.json");pub static ref LOCAL_VSCODE_TASKS_RELATIVE_PATH: &'static Path = Path::new(".vscode/tasks.json");pub static ref TEMP_DIR: PathBuf = if cfg!(target_os = "widows") {- dirs::data_local_dir()+ dirs::cache_dir().expect("failed to determine LocalAppData directory")- .join("Temp/Zed")+ .join("Zed")+ } else if cfg!(target_os = "linux") {+ dirs::cache_dir()+ .expect("failed to determine XDG_CACHE_HOME directory")+ .join("zed")} else {HOME.join(".cache").join("zed")};diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rsindex 7c2111ba82c..d591b0525d8 100644--- a/crates/zed/src/main.rs+++ b/crates/zed/src/main.rs@@ -925,7 +925,11 @@ async fn upload_previous_crashes(let crash_report_url = http.build_zed_api_url("/telemetry/crashes", &[])?;- for dir in [&*CRASHES_DIR, &*CRASHES_RETIRED_DIR] {+ // crash directories are only set on MacOS+ for dir in [&*CRASHES_DIR, &*CRASHES_RETIRED_DIR]+ .iter()+ .filter_map(|d| d.as_deref())+ {let mut children = smol::fs::read_dir(&dir).await?;while let Some(child) = children.next().await {let child = child?;