diff options
author | Felix S. Klock II <[email protected]> | 2019-02-13 16:16:28 +0000 |
---|---|---|
committer | Felix S. Klock II <[email protected]> | 2019-02-13 16:16:28 +0000 |
commit | cfed7c59f49d4a4dd5ac001f520278583c883559 (patch) | |
tree | 80bb5890c434c13697b2aa9bfacb9387d5c3924c /crates | |
parent | a36e310229f13d6959d6ce95c99b659700cefc9a (diff) |
In `RootConfig::contains`, check against canonicalized version of root
path since OS may hand us data that uses that rather than the root as
specified by the user.
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_vfs/src/lib.rs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs index 5d98d905c..2c3c35f28 100644 --- a/crates/ra_vfs/src/lib.rs +++ b/crates/ra_vfs/src/lib.rs | |||
@@ -42,6 +42,8 @@ impl_arena_id!(VfsRoot); | |||
42 | /// returns `true` iff path belongs to the source root | 42 | /// returns `true` iff path belongs to the source root |
43 | pub(crate) struct RootConfig { | 43 | pub(crate) struct RootConfig { |
44 | root: PathBuf, | 44 | root: PathBuf, |
45 | // result of `root.canonicalize()` if that differs from `root`; `None` otherwise. | ||
46 | canonical_root: Option<PathBuf>, | ||
45 | excluded_dirs: Vec<PathBuf>, | 47 | excluded_dirs: Vec<PathBuf>, |
46 | } | 48 | } |
47 | 49 | ||
@@ -58,7 +60,11 @@ impl std::ops::Deref for Roots { | |||
58 | 60 | ||
59 | impl RootConfig { | 61 | impl RootConfig { |
60 | fn new(root: PathBuf, excluded_dirs: Vec<PathBuf>) -> RootConfig { | 62 | fn new(root: PathBuf, excluded_dirs: Vec<PathBuf>) -> RootConfig { |
61 | RootConfig { root, excluded_dirs } | 63 | let mut canonical_root = root.canonicalize().ok(); |
64 | if Some(&root) == canonical_root.as_ref() { | ||
65 | canonical_root = None; | ||
66 | } | ||
67 | RootConfig { root, canonical_root, excluded_dirs } | ||
62 | } | 68 | } |
63 | /// Checks if root contains a path and returns a root-relative path. | 69 | /// Checks if root contains a path and returns a root-relative path. |
64 | pub(crate) fn contains(&self, path: &Path) -> Option<RelativePathBuf> { | 70 | pub(crate) fn contains(&self, path: &Path) -> Option<RelativePathBuf> { |
@@ -66,7 +72,14 @@ impl RootConfig { | |||
66 | if self.excluded_dirs.iter().any(|it| path.starts_with(it)) { | 72 | if self.excluded_dirs.iter().any(|it| path.starts_with(it)) { |
67 | return None; | 73 | return None; |
68 | } | 74 | } |
69 | let rel_path = path.strip_prefix(&self.root).ok()?; | 75 | let rel_path = path.strip_prefix(&self.root) |
76 | .or_else(|err_payload| { | ||
77 | self.canonical_root | ||
78 | .as_ref() | ||
79 | .map_or(Err(err_payload), | ||
80 | |canonical_root| path.strip_prefix(canonical_root)) | ||
81 | }) | ||
82 | .ok()?; | ||
70 | let rel_path = RelativePathBuf::from_path(rel_path).ok()?; | 83 | let rel_path = RelativePathBuf::from_path(rel_path).ok()?; |
71 | 84 | ||
72 | // Ignore some common directories. | 85 | // Ignore some common directories. |