From 602fd58929fa01dd036779b126806fec690811cb Mon Sep 17 00:00:00 2001 From: Uladzislau Kaminski Date: Fri, 23 Feb 2024 17:24:04 +0000 Subject: [PATCH] Fix for toggles on the Welcome page (#8159) Release Notes: The issue is that when welcome page appears settings.json file is not created yet. So the idea of this fix is to create the file in case it is not there yet. - Fixed the toggles on the welcome screen not working if no settings file exists yet. ([#8153](https://github.com/zed-industries/zed/issues/8153)). --------- Co-authored-by: Thorsten Ball Co-authored-by: Marshall --- crates/settings/src/settings_file.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/crates/settings/src/settings_file.rs b/crates/settings/src/settings_file.rs index 7304fc5f1e..b0cc8ade5c 100644 --- a/crates/settings/src/settings_file.rs +++ b/crates/settings/src/settings_file.rs @@ -116,13 +116,20 @@ pub fn update_settings_file( store.new_text_for_update::(old_text, update) })?; let initial_path = paths::SETTINGS.as_path(); - let resolved_path = fs - .canonicalize(initial_path) - .await - .with_context(|| format!("Failed to canonicalize settings path {:?}", initial_path))?; - fs.atomic_write(resolved_path.clone(), new_text) - .await - .with_context(|| format!("Failed to write settings to file {:?}", resolved_path))?; + if !fs.is_file(initial_path).await { + fs.atomic_write(initial_path.to_path_buf(), new_text) + .await + .with_context(|| format!("Failed to write settings to file {:?}", initial_path))?; + } else { + let resolved_path = fs.canonicalize(initial_path).await.with_context(|| { + format!("Failed to canonicalize settings path {:?}", initial_path) + })?; + + fs.atomic_write(resolved_path.clone(), new_text) + .await + .with_context(|| format!("Failed to write settings to file {:?}", resolved_path))?; + } + anyhow::Ok(()) }) .detach_and_log_err(cx);