Skip to content

Add missed unix filetypes (block/char devices, fifos and sockets) #26766

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

Merged
merged 1 commit into from
Jul 9, 2015

Conversation

jespino
Copy link
Contributor

@jespino jespino commented Jul 4, 2015

I find that isn't supported on the current API and I think is necesary.

It is my first PR to rust (I'm not a rust expert and I'm not sure if this is the better way to propose this thinks), of course any suggestion of change will be welcome.

I'm almost sure that in windows aren't supported this filetypes, then, i put in the api of win::fs the functions with a fixed false in the response, I hope this is correct.

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@jespino
Copy link
Contributor Author

jespino commented Jul 4, 2015

Seeing the blame of the libstd/fs.rs file, looks like the correct reviewer could be @alexcrichton

I'm sorry, I read the contribution instructions after the PR.


/// Test whether this file type represents a block device.
#[unstable(feature = "more_filetypes", reason = "recently added API")]
pub fn is_block_device(&self) -> bool { self.0.is_block_device() }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more_filetypes sounds very general. Do you think file_types_posix is a better name? (Just to suggest something too rather than just nitpicking!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

completely agree, I like your name proposal, I'll make a commit to change it. Thanks! 😄

@bluss
Copy link
Member

bluss commented Jul 4, 2015

r? @alexcrichton

Edited: Aha, so it doesn't work if I say it, but that above it what you would say to have rust highfive reassign the issue.

@sfackler sfackler assigned alexcrichton and unassigned nikomatsakis Jul 4, 2015
#[unstable(feature = "file_types_posix", reason = "recently added API")]
pub fn is_block_device(&self) -> bool { false }
#[unstable(feature = "file_types_posix", reason = "recently added API")]
pub fn is_char_device(&self) -> bool { false }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't obviously correct; Windows has device files. For example, NUL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my knowledge about windows is really límited, i going to investigate it and try to propose a solution. Thanks!! 😄

@jespino
Copy link
Contributor Author

jespino commented Jul 5, 2015

I've added a proposal for the windows device file type, but I'm not sure if this is the correct appoach, because my windows knowledge is very limited. I don't know if the windows devices are char devices or block devices, then I have written it to returns true for is_char_device and for is_block_device when is a windows device (this may be wrong, anybody with knowledge about windows that can review this?)

@jespino
Copy link
Contributor Author

jespino commented Jul 5, 2015

I've to define the S_IFSOCK in the liblibc/lib.rs for the different architectures. I'll do it today or tomorrow, I have to investigate the value of the that constants for the different architectures.

@alexcrichton
Copy link
Member

Thanks for the PR! I would expect these functions to appear on a unix-specific extension trait rather than the std::fs surface area. I believe most of these file types aren't available on Windows, and although it's easy to just return false having to opt-in to unix-specific info makes it clear when you do so.

@jespino
Copy link
Contributor Author

jespino commented Jul 5, 2015

Completely agree, I going to rewrite all this as a trait. Thanks!

@jespino jespino force-pushed the add-more-filetypes branch 2 times, most recently from f724501 to 8ede8ee Compare July 5, 2015 21:18
@jespino
Copy link
Contributor Author

jespino commented Jul 5, 2015

I have reset the branch and write again the code. Now is done through a trait.

#[unstable(feature = "file_types_posix", reason = "recently added API")]
pub trait FileTypeUnix {
/// Add special unix types (block/char device, fifo and socket)
#[unstable(feature = "file_types_posix", reason = "recently added API")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should actually be able to omit these unstable tags because #[unstable] inherits (from the trait)

@jespino
Copy link
Contributor Author

jespino commented Jul 6, 2015

Now I thinks is ready and working. @alexcrichton If you want, I can rebase it to master and compact in one commit after your reveiw 😄

#[unstable(feature = "file_type_ext", reason = "recently added API")]
impl FileTypeExt for ::fs::FileType {
fn raw_mode(&self) -> mode_t { self.as_inner().mode }
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably actually avoid this trait impl entirely and instead just making the is method below public and updating the impl in ext/fs.rs to do something like:

pub fn is_foo(&self) -> bool { self.as_inner().is(libc::S_IFFOO) }

@jespino
Copy link
Contributor Author

jespino commented Jul 7, 2015

Changed! 😄

@alexcrichton
Copy link
Member

Looks good to me, thanks @jespino! Flagging as T-libs and I-needs-decision so this comes up during triage.

@alexcrichton alexcrichton added I-needs-decision Issue: In need of a decision. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jul 7, 2015
@jespino
Copy link
Contributor Author

jespino commented Jul 7, 2015

Thanks! Now you have reviewed it, you prefer I leave the commits as are now, or you prefer I rebase it from master and compact everything in one commit?

@alexcrichton
Copy link
Member

It's fine to leave as-is, I think there may be a few more minor updates that come through (e.g. docs) so the squashing can happen later.

@alexcrichton
Copy link
Member

Ok we discussed this at triage today and the decision was to go ahead and just r+, I'll leave a few more comments and then I think this is good to go after a rebase.

@@ -178,6 +179,23 @@ impl MetadataExt for fs::Metadata {
}
}

#[unstable(feature = "file_type_ext", reason = "recently added API")]
pub trait FileTypeExt {
/// Add special unix types (block/char device, fifo and socket)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment I believe should be placed on the trait itself. Also could you add documentation for each of these methods to say what it's doing?

@jespino jespino force-pushed the add-more-filetypes branch from 5d8210f to 74f4298 Compare July 9, 2015 08:30
@jespino
Copy link
Contributor Author

jespino commented Jul 9, 2015

Rebased to master, compacted in one commit, and rewritten the doc comments.

@alexcrichton
Copy link
Member

@bors: r+ 74f4298

Thanks!

bors added a commit that referenced this pull request Jul 9, 2015
I find that isn't supported on the current API and I think is necesary.

It is my first PR to rust (I'm not a rust expert and I'm not sure if this is the better way to propose this thinks), of course any suggestion of change will be welcome.

I'm almost sure that in windows aren't supported this filetypes, then, i put in the api of win::fs the functions with a fixed false in the response, I hope this is correct.
@bors
Copy link
Collaborator

bors commented Jul 9, 2015

⌛ Testing commit 74f4298 with merge 6c4e236...

@alexcrichton alexcrichton removed the I-needs-decision Issue: In need of a decision. label Jul 9, 2015
@bors bors merged commit 74f4298 into rust-lang:master Jul 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants