-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Suggested lint: use "!is_dir()" instead of "is_file()" #4503
Comments
I would like to take a stab of this, are there any pointers? |
Failed to setup toolchain, My country has blocked the Amazon AWS, so I can't download the master toolchain. Are there other any options to setup the tool chain? ./setup-toolchain.sh
detecting the channel of the `824383d4ab66abd32abc6e19b68d78ecfddcb7d4` toolchain...
downloading <https://rust-lang-ci2.s3-us-west-1.amazonaws.com/rustc-builds/824383d4ab66abd32abc6e19b68d78ecfddcb7d4/rustc-nightly-x86_64-unknown-linux-gnu.tar.xz>...
143.48 KB / 66.00 MB [>---------------------------------------------------------------------------------------------------------------] 0.21 % 23.91 KB/s 47m
error: failed to unpack `rustc-nightly-x86_64-unknown-linux-gnu/rustc/bin/rustdoc` into `master/bin/rustdoc`
error: toolchain 'master' is not installed |
The only other way, I know of is to compile rustc yourself. This is really slow though (~2h compile time). The current Clippy master (58e01ea) should be compileable with nightly-2019-09-09 toolchain. You can work from there. If there are any conflicts we can try to resolve them for you, once you have a PR ready |
Ok, thank you, @flip1995. |
There is a file name Would |
Don't remove it in the PR. You can remove it locally. FYI: You can always ignore the $ cargo +toochain-name build in your case: $ cargo +nightly-2019-09-09 build (also works with test/check/clippy/...) |
Ok, thank you. |
A lot of people have a tendency to assume files and directories are all there are they have to think about, and that if its not a file, its clearly a directory, and vice versa.
The documentation even suggests this if you don't think it through, by saying that
is_file()
andis_dir()
are mutually exclusive.However, not all things that return false from
is_file()
are directories, and plenty of special file types return false for bothis_dir()
andis_file()
A lot of the time, when people make the
is_file()
check, they're not asking "is this a regular file as opposed to a special one", they're asking "is this a thing that I can read and get bytes from".A particular situation where one might be calling
is_file()
and prematurely rejecting it is when the file in question is a user specified path, and that specified path is a pipe, as constructed by the bash command:fooprogram <( program that outputs )
fooprogram
gets passed/dev/fd/63
(or similar) as the first parameter, and that is not a regular file, but it is for all general purposes something that can be safely treated as a file.Subsequently, the better advice here is to check for
if !file.is_dir()
in preparation for doing reads from it.Excerpts from
man 7 inode
strace output of an example of this usage (noting the value of st_mode):
Current rust code for sys::unix::fs::FileType
https://github.com/rust-lang/rust/blob/a24f636e60a5da57ab641d800ac5952bbde98b65/src/libstd/sys/unix/fs.rs#L195-L201
But it may be worth noting the users assumptions do seem to hold true on Windows, where "is_file()" is just shorthand for "!is_symlink() && !is_directory()". But even then, if you're only asking "Can I read a thing", the "!is_symlink()" check is something you don't want to be doing, so even there, the "!is_dir()" is possibly the right call. Ugh.
https://github.com/rust-lang/rust/blob/a24f636e60a5da57ab641d800ac5952bbde98b65/src/libstd/sys/windows/fs.rs#L586-L617
The text was updated successfully, but these errors were encountered: