From 72fe70f2f8aee9556166ba0f984a29d19a485e61 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 26 Jun 2020 16:25:08 +0200 Subject: Make VFS join methods fallible --- crates/vfs/src/vfs_path.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'crates/vfs/src/vfs_path.rs') 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 { VfsPathRepr::VirtualPath(_) => None, } } - pub fn join(&self, path: &str) -> VfsPath { + pub fn join(&self, path: &str) -> Option { match &self.0 { VfsPathRepr::PathBuf(it) => { let res = it.join(path).normalize(); - VfsPath(VfsPathRepr::PathBuf(res)) + Some(VfsPath(VfsPathRepr::PathBuf(res))) } VfsPathRepr::VirtualPath(it) => { - let res = it.join(path); - VfsPath(VfsPathRepr::VirtualPath(res)) + let res = it.join(path)?; + Some(VfsPath(VfsPathRepr::VirtualPath(res))) } } } @@ -101,13 +101,15 @@ impl VirtualPath { self.0 = self.0[..pos].to_string(); true } - fn join(&self, mut path: &str) -> VirtualPath { + fn join(&self, mut path: &str) -> Option { let mut res = self.clone(); while path.starts_with("../") { - assert!(res.pop()); + if !res.pop() { + return None; + } path = &path["../".len()..] } res.0 = format!("{}/{}", res.0, path); - res + Some(res) } } -- cgit v1.2.3