-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
42f4dd0
Implement RFC 1252 expanding the OpenOptions structure
pitdicker 7a1817c
Move `custom_flags` to `OpenOptionsExt`
pitdicker 1230a08
Fix doctests
pitdicker 9c56918
Addressed comments
pitdicker ae30294
Remove raw pointer from OpenOptions struct
pitdicker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,15 +99,49 @@ pub trait OpenOptionsExt { | |
/// | ||
/// If a new file is created as part of a `File::open_opts` call then this | ||
/// specified `mode` will be used as the permission bits for the new file. | ||
/// If no `mode` is set, the default of `0o666` will be used. | ||
/// The operating system masks out bits with the systems `umask`, to produce | ||
/// the final permissions. | ||
#[stable(feature = "fs_ext", since = "1.1.0")] | ||
fn mode(&mut self, mode: raw::mode_t) -> &mut Self; | ||
|
||
/// Pass custom flags to the `flags` agument of `open`. | ||
/// | ||
/// The bits that define the access mode are masked out with `O_ACCMODE`, to | ||
/// ensure they do not interfere with the access mode set by Rusts options. | ||
/// | ||
/// Custom flags can only set flags, not remove flags set by Rusts options. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this clarify that any previously set custom flags are overwritten? |
||
/// This options overwrites any previously set custom flags. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ```rust,ignore | ||
/// extern crate libc; | ||
/// use std::fs::OpenOptions; | ||
/// use std::os::unix::fs::OpenOptionsExt; | ||
/// | ||
/// let mut options = OpenOptions::new(); | ||
/// options.write(true); | ||
/// if cfg!(unix) { | ||
/// options.custom_flags(libc::O_NOFOLLOW); | ||
/// } | ||
/// let file = options.open("foo.txt"); | ||
/// ``` | ||
#[unstable(feature = "expand_open_options", | ||
reason = "recently added", | ||
issue = "30014")] | ||
fn custom_flags(&mut self, flags: i32) -> &mut Self; | ||
} | ||
|
||
#[stable(feature = "fs_ext", since = "1.1.0")] | ||
impl OpenOptionsExt for OpenOptions { | ||
fn mode(&mut self, mode: raw::mode_t) -> &mut OpenOptions { | ||
self.as_inner_mut().mode(mode); self | ||
} | ||
|
||
fn custom_flags(&mut self, flags: i32) -> &mut OpenOptions { | ||
self.as_inner_mut().custom_flags(flags); self | ||
} | ||
} | ||
|
||
// Hm, why are there casts here to the returned type, shouldn't the types always | ||
|
@@ -262,4 +296,3 @@ impl DirBuilderExt for fs::DirBuilder { | |
self | ||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this explicitly call out the error mode of failing if the file already exists? (e.g. also calling out that it's atomic)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
O, of course. That is practically its only reason of existence :)