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

Remove thread-blocking call to libc::stat in Path::stat #9958

Closed
alexcrichton opened this issue Oct 19, 2013 · 8 comments · Fixed by #10022
Closed

Remove thread-blocking call to libc::stat in Path::stat #9958

alexcrichton opened this issue Oct 19, 2013 · 8 comments · Fixed by #10022
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@alexcrichton
Copy link
Member

This should instead use the rt::io::file interface which does not block the thread. Additionally, this should remove the default_stat functions in the path/mod.rs file 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!

@hatahet
Copy link
Contributor

hatahet commented Oct 20, 2013

What about calls to lstat() in path/posix.rs?

@hatahet
Copy link
Contributor

hatahet commented Oct 20, 2013

It seems that there is no 1-to-1 mapping of libc::stat to rt::io::FileStat. Particularly, the latter is missing fields, such as mode, and OS-specific attributes, such as birthtime on MacOS and FreeBSD. I suppose that FileStat will have to have those fields added to it.

@alexcrichton
Copy link
Member Author

The lstat function should not exist in that current form, and it's fine to drop fields for now. A rust Path should work the same on all platforms, not create different structs with different fields (very easy to miscompile on other platforms).

@hatahet
Copy link
Contributor

hatahet commented Oct 21, 2013

When I changed the implementation of Path::stat() in posix.rs to call rt::io::file::stat() and then make 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:395

I do have an export RUST_LOG=rustc=1, but nothing extra seems to be printed. Should I file a separate issue for this?

@alexcrichton
Copy link
Member Author

The calls to rt::io::file::stat will raise on the io_error condition when they encounter an error. In this case it looks like the error was that a file was not found. The return value of stat will be None, but you'll need to explicitly catch the error as well for now (and ignore it or continue to propagate it).

@hatahet
Copy link
Contributor

hatahet commented Oct 22, 2013

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:587 we have assert_eq!(parent_stat.st_dev, child_stat.st_dev); for two tests: test_keep_current_working_dir() and test_change_working_directory

@hatahet
Copy link
Contributor

hatahet commented Oct 22, 2013

Both the fields in question exist in uv_stat_t, I suppose I will just add them to FileStat then in that case.

@alexcrichton
Copy link
Member Author

Feel free to modify FileStat as much as you need, especially if there's information inside of uv_stat_t on all platforms, then feel free to add it in!

@bors bors closed this as completed in 60245b9 Oct 23, 2013
flip1995 pushed a commit to flip1995/rust that referenced this issue Dec 17, 2022
flip1995 pushed a commit to flip1995/rust that referenced this issue Dec 17, 2022
Fix rust-lang#9958

This PR fixes rust-lang#9958. In order to fix the issue, the lint will now peel reference operators and enclose the expression with parentheses when necessary.

changelog: [`comparison_to_empty`]: Peel deref operators in suggestions when necessary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants