aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-02-13 21:33:31 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-02-13 21:33:31 +0000
commitebfa26658e9f65491e79f6853bb7c77030f5b0fe (patch)
tree2c0d36ffc23e1b0db34608fd694a985edad9ccab
parentcb4327b3a9f0858235dc20b7c5c7e25c6c330aab (diff)
parentda300fd55340ca1c65914744fa30c2b3b02e485f (diff)
Merge #818
818: In `RootConfig::contains`, check against canonicalized version of root path r=matklad a=pnkfelix In `RootConfig::contains`, check against canonicalized version of root path since OS may hand us data that uses the canonical form rather than the root as specified by the user. This is a step towards a resolution of issue #734 but does not completely fix the problem there. Co-authored-by: Felix S. Klock II <[email protected]>
-rw-r--r--crates/ra_vfs/src/lib.rs17
1 files changed, 15 insertions, 2 deletions
diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs
index 3dd05197e..f07657db6 100644
--- a/crates/ra_vfs/src/lib.rs
+++ b/crates/ra_vfs/src/lib.rs
@@ -44,6 +44,8 @@ impl_arena_id!(VfsRoot);
44/// returns `true` iff path belongs to the source root 44/// returns `true` iff path belongs to the source root
45pub(crate) struct RootConfig { 45pub(crate) struct RootConfig {
46 root: PathBuf, 46 root: PathBuf,
47 // result of `root.canonicalize()` if that differs from `root`; `None` otherwise.
48 canonical_root: Option<PathBuf>,
47 excluded_dirs: Vec<PathBuf>, 49 excluded_dirs: Vec<PathBuf>,
48} 50}
49 51
@@ -60,7 +62,11 @@ impl std::ops::Deref for Roots {
60 62
61impl RootConfig { 63impl RootConfig {
62 fn new(root: PathBuf, excluded_dirs: Vec<PathBuf>) -> RootConfig { 64 fn new(root: PathBuf, excluded_dirs: Vec<PathBuf>) -> RootConfig {
63 RootConfig { root, excluded_dirs } 65 let mut canonical_root = root.canonicalize().ok();
66 if Some(&root) == canonical_root.as_ref() {
67 canonical_root = None;
68 }
69 RootConfig { root, canonical_root, excluded_dirs }
64 } 70 }
65 /// Checks if root contains a path and returns a root-relative path. 71 /// Checks if root contains a path and returns a root-relative path.
66 pub(crate) fn contains(&self, path: &Path) -> Option<RelativePathBuf> { 72 pub(crate) fn contains(&self, path: &Path) -> Option<RelativePathBuf> {
@@ -68,7 +74,14 @@ impl RootConfig {
68 if self.excluded_dirs.iter().any(|it| path.starts_with(it)) { 74 if self.excluded_dirs.iter().any(|it| path.starts_with(it)) {
69 return None; 75 return None;
70 } 76 }
71 let rel_path = path.strip_prefix(&self.root).ok()?; 77 let rel_path = path
78 .strip_prefix(&self.root)
79 .or_else(|err_payload| {
80 self.canonical_root
81 .as_ref()
82 .map_or(Err(err_payload), |canonical_root| path.strip_prefix(canonical_root))
83 })
84 .ok()?;
72 let rel_path = RelativePathBuf::from_path(rel_path).ok()?; 85 let rel_path = RelativePathBuf::from_path(rel_path).ok()?;
73 86
74 // Ignore some common directories. 87 // Ignore some common directories.