pub fn chdir_internal(env: &WasiEnv, path: &str) -> Result<(), Errno>Expand description
Change the WASIX current directory to the directory reached by resolving
path.
chdir is intentionally not a textual path update. POSIX shells often keep
a logical $PWD for display, so after cd some_symlink a shell builtin
pwd may print the symlinked spelling. The process current directory,
though, is the resolved directory object. A physical lookup such as
realpath(".") observes the symlink target. WASIX stores the latter form in
state.fs.current_dir, because this string is used by the runtime to resolve
future relative paths, not merely to echo the spelling the user typed.
The resolver is called with follow_symlinks = true, matching chdir(2):
the final component must be followed if it is a symlink, and the resolved
inode must be a directory. The stored cwd therefore comes from the resolved
Kind::Dir path (or / for the virtual root), not from the original input
path or its lexical absolute form. Preserving the logical input here would
make later relative lookups re-enter symlink paths and would diverge from the
directory object that chdir actually selected.
For resolved non-root directories, the final read_dir check refreshes the
backing filesystem view enough to reject stale cached directories that can no
longer be listed.