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

Implement RFC 1252 expanding the OpenOptions structure #30872

Merged
merged 5 commits into from
Jan 20, 2016
Merged

Implement RFC 1252 expanding the OpenOptions structure #30872

merged 5 commits into from
Jan 20, 2016

Conversation

pitdicker
Copy link
Contributor

Tracking issue: #30014

This implements the RFC and makes a few other changes.
I have added a few extra tests, and made the Windows and
Unix code as similar as possible.

Part of the RFC mentions the unstable OpenOptionsExt trait
on Windows (see #27720). I have added a few extra methods
to future-proof it for CreateFile2.

Tracking issue: #30014

This implements the RFC and makes a few other changes.
I have added a few extra tests, and made the Windows and
Unix code as similar as possible.

Part of the RFC mentions the unstable OpenOptionsExt trait
on Windows (see #27720). I have added a few extra methods
to future-proof it for CreateFile2.
@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @aturon (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. Due to 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.

@retep998
Copy link
Member

I feel really uncomfortable about custom_flags being an inherent method and not an OS specific extension trait. Since the meaning of flags passed to custom_flags depends on which platform you're on, people will need to use cfg to choose which flags to pass anyway, so it really should be part of the extension traits.

///
/// let file = OpenOptions::new().write(true).create_new(true).open("foo.txt");
/// ```
#[stable(feature = "expand_open_options", since = "1.7.0")]
Copy link
Member

Choose a reason for hiding this comment

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

This should probably start out unstable for now.

@pitdicker
Copy link
Contributor Author

Now that you say that custom_flags should be part of the extension traits, it seems obvious to me. I will change it.

@pitdicker
Copy link
Contributor Author

Do new methods need to be unstable if they have a accepted rfc?

@retep998
Copy link
Member

New methods should always start out unstable if possible, even if there is an accepted RFC.

And mark the new methods as unstable.
@@ -413,6 +414,9 @@ impl OpenOptions {
/// This option, when true, will indicate that the file should be
/// `write`-able if opened.
///
/// If a file already exist, the contents of that file get overwritten, but it is
/// not truncated.
Copy link
Member

Choose a reason for hiding this comment

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

Could this clarify that the contents don't get immediately overwritten, only when an actual call to write is made? E.g. emphasize that the cursor is at the beginning so written data will tromp existing data.

Also as a side note could you make sure to format this comment and the ones below to 80 characters in width? (the style of the surrounding module)

@alexcrichton
Copy link
Member

This looks excellent to me, thanks @pitdicker!

@pitdicker
Copy link
Contributor Author

Should I mention it is updated?

attributes: c::DWORD,
share_mode: c::DWORD,
security_qos_flags: c::DWORD,
security_attributes: c::LPSECURITY_ATTRIBUTES,
Copy link
Member

Choose a reason for hiding this comment

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

I think that this inclusion of a pointer may actually affect whether OpenOptions is Send and Sync, could you add a test to make sure that it's the same after this commit as it is today? (I believe it's both Send and Sync today)

@alexcrichton
Copy link
Member

Ah yes thanks for the ping (definitely useful as github notifications don't go out for updates to the branch).

Just one small nit from me and otherwise I believe this is good to go!

@pitdicker
Copy link
Contributor Author

Thanks for the reviews! Ik can do some digging, but am not that good at coding :).

I am not sure how to test for send and sync. Hoe should I do that?
Maybe it is better to remove the pointer for now, as the function to set also removed.

@alexcrichton
Copy link
Member

You can probably add something like this to src/libstd/fs.rs:

fn _assert_send_sync() {
    fn _assert_send_sync<T: Send + Sync>() {}
    _assert_send_sync::<OpenOptions>();
}

Otherwise it is not Send and Sync anymore
@pitdicker
Copy link
Contributor Author

Good catch, it did lose Send and Sync. Updated.

@alexcrichton
Copy link
Member

@bors: r+ ae30294

Thanks again @pitdicker!

Taggings as relnotes as this tweaks the behavior of OpenOptions in some corner cases to be consistent across platforms.

bors added a commit that referenced this pull request Jan 20, 2016
Tracking issue: #30014

This implements the RFC and makes a few other changes.
I have added a few extra tests, and made the Windows and
Unix code as similar as possible.

Part of the RFC mentions the unstable OpenOptionsExt trait
on Windows (see #27720). I have added a few extra methods
to future-proof it for CreateFile2.
@bors
Copy link
Contributor

bors commented Jan 20, 2016

⌛ Testing commit ae30294 with merge 292af75...

@alexcrichton alexcrichton added the relnotes Marks issues that should be documented in the release notes of the next release. label Jan 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes Marks issues that should be documented in the release notes of the next release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants