Repository navigation
Remove thread-blocking call to libc::stat in Path::stat #9958
Description
Activity
What about calls to
lstat()inpath/posix.rs?It seems that there is no 1-to-1 mapping of
libc::stattort::io::FileStat. Particularly, the latter is missing fields, such asmode, and OS-specific attributes, such asbirthtimeon MacOS and FreeBSD. I suppose thatFileStatwill have to have those fields added to it.The
lstatfunction should not exist in that current form, and it's fine to drop fields for now. A rustPathshould work the same on all platforms, not create different structs with different fields (very easy to miscompile on other platforms).When I changed the implementation of
Path::stat()inposix.rsto callrt::io::file::stat()and thenmake check, I hit a compiler error:task '<unnamed>' failed at 'Unhandled condition: io_error: rt::io::IoError{kind: OtherIoError, desc: "no such file or directory", detail: None}', /Users/.../dev/local/github/rust/src/libstd/condition.rs:131 error: internal compiler error: unexpected failure note: the compiler hit an unexpected failure path. this is a bug note: try running with RUST_LOG=rustc=1 to get further details and report the results to github.com/mozilla/rust/issues task '<unnamed>' failed at 'explicit failure', /Users/.../dev/local/github/rust/src/librustc/rustc.rs:395I do have an
export RUST_LOG=rustc=1, but nothing extra seems to be printed. Should I file a separate issue for this?The calls to
rt::io::file::statwill raise on theio_errorcondition when they encounter an error. In this case it looks like the error was that a file was not found. The return value ofstatwill beNone, but you'll need to explicitly catch the error as well for now (and ignore it or continue to propagate it).If it is fine to drop fields for now, I suppose we should remove tests that reference such fields. E.g. in
libstd/run.rs:587we haveassert_eq!(parent_stat.st_dev, child_stat.st_dev);for two tests:test_keep_current_working_dir()andtest_change_working_directoryBoth the fields in question exist in
uv_stat_t, I suppose I will just add them toFileStatthen in that case.Feel free to modify
FileStatas much as you need, especially if there's information inside ofuv_stat_ton all platforms, then feel free to add it in!- added 2 commits that reference this issue
on Dec 17, 2022
This should instead use the
rt::io::fileinterface which does not block the thread. Additionally, this should remove thedefault_statfunctions in thepath/mod.rsfile along with related definitions.This is a pretty good first project for anyone wanting to sink their teeth into some library work! It's a bit of refactoring and should result in a nice large negative diffstat!