From f1de13382022143c5ab24758fa60541d4254316a Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 27 Mar 2023 21:55:02 +0200 Subject: [PATCH] Canonicalize rust-project.json manifest path --- crates/paths/src/lib.rs | 5 +++++ crates/project-model/src/manifest_path.rs | 5 +++++ crates/project-model/src/workspace.rs | 9 ++------- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/crates/paths/src/lib.rs b/crates/paths/src/lib.rs index 6ae23ac841a..ac09121aedf 100644 --- a/crates/paths/src/lib.rs +++ b/crates/paths/src/lib.rs @@ -166,6 +166,11 @@ pub fn to_path_buf(&self) -> AbsPathBuf { AbsPathBuf::try_from(self.0.to_path_buf()).unwrap() } + /// Equivalent of [`Path::canonicalize`] for `AbsPath`. + pub fn canonicalize(&self) -> Result { + Ok(self.as_ref().canonicalize()?.try_into().unwrap()) + } + /// Equivalent of [`Path::strip_prefix`] for `AbsPath`. /// /// Returns a relative path. diff --git a/crates/project-model/src/manifest_path.rs b/crates/project-model/src/manifest_path.rs index 980d92d3df9..d6754116e60 100644 --- a/crates/project-model/src/manifest_path.rs +++ b/crates/project-model/src/manifest_path.rs @@ -34,6 +34,11 @@ impl ManifestPath { pub fn parent(&self) -> &AbsPath { self.file.parent().unwrap() } + + /// Equivalent of [`Path::canonicalize`] for `ManifestPath`. + pub fn canonicalize(&self) -> Result { + Ok((&**self).canonicalize()?.try_into().unwrap()) + } } impl ops::Deref for ManifestPath { diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs index 916447fdffa..199fa1e5c2c 100644 --- a/crates/project-model/src/workspace.rs +++ b/crates/project-model/src/workspace.rs @@ -4,7 +4,7 @@ use std::{collections::VecDeque, fmt, fs, process::Command, sync::Arc}; -use anyhow::{bail, format_err, Context, Result}; +use anyhow::{format_err, Context, Result}; use base_db::{ CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, Edition, Env, FileId, LangCrateOrigin, ProcMacroPaths, TargetLayoutLoadResult, @@ -154,12 +154,7 @@ pub fn load( ) -> Result { let res = match manifest { ProjectManifest::ProjectJson(project_json) => { - let metadata = fs::symlink_metadata(&project_json).with_context(|| { - format!("Failed to read json file {}", project_json.display()) - })?; - if metadata.is_symlink() { - bail!("The project-json may not currently point to a symlink"); - } + let project_json = project_json.canonicalize()?; let file = fs::read_to_string(&project_json).with_context(|| { format!("Failed to read json file {}", project_json.display()) })?;