diff --git a/src/platform/redox/path.rs b/src/platform/redox/path.rs index 45e3e7bbaaab0ebd45113b909b81c957a8c5462f..fd2cc613ba6edcbaf1164fced23bde125038dc97 100644 --- a/src/platform/redox/path.rs +++ b/src/platform/redox/path.rs @@ -1,3 +1,4 @@ +use syscall::data::Stat; use syscall::error::*; use syscall::flag::*; @@ -95,6 +96,13 @@ pub fn chdir(path: &str) -> Result<()> { let canonicalized = canonicalize_using_cwd(cwd_guard.as_deref(), path).ok_or(Error::new(ENOENT))?; + let fd = syscall::open(&canonicalized, O_STAT | O_CLOEXEC)?; + let mut stat = Stat::default(); + if syscall::fstat(fd, &mut stat).is_err() || (stat.st_mode & MODE_TYPE) != MODE_DIR { + return Err(Error::new(ENOTDIR)); + } + let _ = syscall::close(fd); + *cwd_guard = Some(canonicalized.into_boxed_str()); // TODO: Check that the dir exists and is a directory.