Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update cd command to use correct path traversal from the path crate to allow for parent directory #1104

Merged
merged 16 commits into from
Sep 9, 2024
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
Loading