Skip to content

Commit

Permalink
Use Path::get() in chdir function to support .. path nav (#1104)
Browse files Browse the repository at this point in the history
  • Loading branch information
nnh12 authored Sep 9, 2024
1 parent 68cc3ae commit ee7688f
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions kernel/environment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,14 @@ impl Environment {
/// Changes the current working directory.
#[doc(alias("change"))]
pub fn chdir(&mut self, path: &Path) -> Result<()> {
for component in path.components() {
let new = self.working_dir.lock().get(component.as_ref());
match new {
Some(FileOrDir::Dir(dir)) => {
self.working_dir = dir;
}
Some(FileOrDir::File(_)) => return Err(Error::NotADirectory),
None => return Err(Error::NotFound),
match path.get(&self.working_dir) {
Some(FileOrDir::Dir(dir)) => {
self.working_dir = dir;
Ok(())
}
Some(FileOrDir::File(_)) => Err(Error::NotADirectory),
None => Err(Error::NotFound),
}
Ok(())
}

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

0 comments on commit ee7688f

Please sign in to comment.