Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
paths: Fix using relative path as custom_data_dir (#35256)
devjasperwang2fced602b805
diff --git a/crates/paths/src/paths.rs b/crates/paths/src/paths.rsindex 2f3b1889807..47a0f12c063 100644--- a/crates/paths/src/paths.rs+++ b/crates/paths/src/paths.rs@@ -35,6 +35,7 @@ pub fn remote_server_dir_relative() -> &'static Path {/// Sets a custom directory for all user data, overriding the default data directory./// This function must be called before any other path operations that depend on the data directory.+/// The directory's path will be canonicalized to an absolute path by a blocking FS operation./// The directory will be created if it doesn't exist.////// # Arguments@@ -50,13 +51,20 @@ pub fn remote_server_dir_relative() -> &'static Path {////// Panics if:/// * Called after the data directory has been initialized (e.g., via `data_dir` or `config_dir`)+/// * The directory's path cannot be canonicalized to an absolute path/// * The directory cannot be createdpub fn set_custom_data_dir(dir: &str) -> &'static PathBuf {if CURRENT_DATA_DIR.get().is_some() || CONFIG_DIR.get().is_some() {panic!("set_custom_data_dir called after data_dir or config_dir was initialized");}CUSTOM_DATA_DIR.get_or_init(|| {- let path = PathBuf::from(dir);+ let mut path = PathBuf::from(dir);+ if path.is_relative() {+ let abs_path = path+ .canonicalize()+ .expect("failed to canonicalize custom data directory's path to an absolute path");+ path = PathBuf::from(util::paths::SanitizedPath::from(abs_path))+ }std::fs::create_dir_all(&path).expect("failed to create custom data directory");path})