aboutsummaryrefslogtreecommitdiff
path: root/crates/vfs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-06-26 15:37:15 +0100
committerGitHub <[email protected]>2020-06-26 15:37:15 +0100
commit4f60b4f2a32190830215defe6cf81836f34d99c9 (patch)
tree008a5cf106fd62a65b1931cf340cf058a838be5d /crates/vfs
parentce06f8d0416d5851264769eb9583ce43d66f0474 (diff)
parent72fe70f2f8aee9556166ba0f984a29d19a485e61 (diff)
Merge #5076
5076: Make VFS join methods fallible r=matklad a=jonas-schievink Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/vfs')
-rw-r--r--crates/vfs/src/file_set.rs2
-rw-r--r--crates/vfs/src/vfs_path.rs16
2 files changed, 10 insertions, 8 deletions
diff --git a/crates/vfs/src/file_set.rs b/crates/vfs/src/file_set.rs
index 0173f7464..d0ddeafe7 100644
--- a/crates/vfs/src/file_set.rs
+++ b/crates/vfs/src/file_set.rs
@@ -18,7 +18,7 @@ impl FileSet {
18 pub fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> { 18 pub fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> {
19 let mut base = self.paths[&anchor].clone(); 19 let mut base = self.paths[&anchor].clone();
20 base.pop(); 20 base.pop();
21 let path = base.join(path); 21 let path = base.join(path)?;
22 let res = self.files.get(&path).copied(); 22 let res = self.files.get(&path).copied();
23 res 23 res
24 } 24 }
diff --git a/crates/vfs/src/vfs_path.rs b/crates/vfs/src/vfs_path.rs
index 940f91d0e..dc3031ada 100644
--- a/crates/vfs/src/vfs_path.rs
+++ b/crates/vfs/src/vfs_path.rs
@@ -22,15 +22,15 @@ impl VfsPath {
22 VfsPathRepr::VirtualPath(_) => None, 22 VfsPathRepr::VirtualPath(_) => None,
23 } 23 }
24 } 24 }
25 pub fn join(&self, path: &str) -> VfsPath { 25 pub fn join(&self, path: &str) -> Option<VfsPath> {
26 match &self.0 { 26 match &self.0 {
27 VfsPathRepr::PathBuf(it) => { 27 VfsPathRepr::PathBuf(it) => {
28 let res = it.join(path).normalize(); 28 let res = it.join(path).normalize();
29 VfsPath(VfsPathRepr::PathBuf(res)) 29 Some(VfsPath(VfsPathRepr::PathBuf(res)))
30 } 30 }
31 VfsPathRepr::VirtualPath(it) => { 31 VfsPathRepr::VirtualPath(it) => {
32 let res = it.join(path); 32 let res = it.join(path)?;
33 VfsPath(VfsPathRepr::VirtualPath(res)) 33 Some(VfsPath(VfsPathRepr::VirtualPath(res)))
34 } 34 }
35 } 35 }
36 } 36 }
@@ -101,13 +101,15 @@ impl VirtualPath {
101 self.0 = self.0[..pos].to_string(); 101 self.0 = self.0[..pos].to_string();
102 true 102 true
103 } 103 }
104 fn join(&self, mut path: &str) -> VirtualPath { 104 fn join(&self, mut path: &str) -> Option<VirtualPath> {
105 let mut res = self.clone(); 105 let mut res = self.clone();
106 while path.starts_with("../") { 106 while path.starts_with("../") {
107 assert!(res.pop()); 107 if !res.pop() {
108 return None;
109 }
108 path = &path["../".len()..] 110 path = &path["../".len()..]
109 } 111 }
110 res.0 = format!("{}/{}", res.0, path); 112 res.0 = format!("{}/{}", res.0, path);
111 res 113 Some(res)
112 } 114 }
113} 115}