Skip to content

Commit ee7688f

Browse files
authored
Use Path::get() in chdir function to support .. path nav (#1104)
1 parent 68cc3ae commit ee7688f

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

kernel/environment/src/lib.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,14 @@ impl Environment {
3131
/// Changes the current working directory.
3232
#[doc(alias("change"))]
3333
pub fn chdir(&mut self, path: &Path) -> Result<()> {
34-
for component in path.components() {
35-
let new = self.working_dir.lock().get(component.as_ref());
36-
match new {
37-
Some(FileOrDir::Dir(dir)) => {
38-
self.working_dir = dir;
39-
}
40-
Some(FileOrDir::File(_)) => return Err(Error::NotADirectory),
41-
None => return Err(Error::NotFound),
34+
match path.get(&self.working_dir) {
35+
Some(FileOrDir::Dir(dir)) => {
36+
self.working_dir = dir;
37+
Ok(())
4238
}
39+
Some(FileOrDir::File(_)) => Err(Error::NotADirectory),
40+
None => Err(Error::NotFound),
4341
}
44-
Ok(())
4542
}
4643

4744
/// Returns the value of the environment variable with the given `key`.

0 commit comments

Comments
 (0)