From ba4588e84fdb8260867a346dd7a92ae2e9454e77 Mon Sep 17 00:00:00 2001 From: Jeremy Soller <jackpot51@gmail.com> Date: Tue, 10 Jan 2017 09:22:59 -0700 Subject: [PATCH] Simplify path parsing --- src/context/context.rs | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/src/context/context.rs b/src/context/context.rs index 54abd3d6..55af1ca0 100644 --- a/src/context/context.rs +++ b/src/context/context.rs @@ -126,27 +126,19 @@ impl Context { pub fn canonicalize(&self, path: &[u8]) -> Vec<u8> { let mut canon = if path.iter().position(|&b| b == b':').is_none() { let cwd = self.cwd.lock(); - if path == b"." { - cwd.clone() - } else if path == b".." { - cwd[..cwd[..cwd.len() - 1] - .iter().rposition(|&b| b == b'/' || b == b':') - .map_or(cwd.len(), |i| i + 1)] - .to_vec() + + let mut canon = if !path.starts_with(b"/") { + let mut c = cwd.clone(); + if ! c.ends_with(b"/") { + c.push(b'/'); + } + c } else { - let mut canon = if !path.starts_with(b"/") { - let mut c = cwd.clone(); - if ! c.ends_with(b"/") { - c.push(b'/'); - } - c - } else { - cwd[..cwd.iter().position(|&b| b == b':').map_or(1, |i| i + 1)].to_vec() - }; + cwd[..cwd.iter().position(|&b| b == b':').map_or(1, |i| i + 1)].to_vec() + }; - canon.extend_from_slice(&path); - canon - } + canon.extend_from_slice(&path); + canon } else { path.to_vec() }; -- GitLab