Skip to content
Snippets Groups Projects
Commit ba4588e8 authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Simplify path parsing

parent 433746e1
No related branches found
No related tags found
No related merge requests found
...@@ -126,27 +126,19 @@ impl Context { ...@@ -126,27 +126,19 @@ impl Context {
pub fn canonicalize(&self, path: &[u8]) -> Vec<u8> { pub fn canonicalize(&self, path: &[u8]) -> Vec<u8> {
let mut canon = if path.iter().position(|&b| b == b':').is_none() { let mut canon = if path.iter().position(|&b| b == b':').is_none() {
let cwd = self.cwd.lock(); let cwd = self.cwd.lock();
if path == b"." {
cwd.clone() let mut canon = if !path.starts_with(b"/") {
} else if path == b".." { let mut c = cwd.clone();
cwd[..cwd[..cwd.len() - 1] if ! c.ends_with(b"/") {
.iter().rposition(|&b| b == b'/' || b == b':') c.push(b'/');
.map_or(cwd.len(), |i| i + 1)] }
.to_vec() c
} else { } else {
let mut canon = if !path.starts_with(b"/") { cwd[..cwd.iter().position(|&b| b == b':').map_or(1, |i| i + 1)].to_vec()
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()
};
canon.extend_from_slice(&path); canon.extend_from_slice(&path);
canon canon
}
} else { } else {
path.to_vec() path.to_vec()
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment