Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upDocument and expand the open options #1252
Conversation
pitdicker
referenced this pull request
Aug 13, 2015
Closed
Fix different behaviour of OpenOptions between Windows en Linux #26772
nrc
added
the
T-libs
label
Aug 13, 2015
This comment has been minimized.
This comment has been minimized.
|
@pitdicker Thanks so much for taking this on; it's clearly a huge amount of work! I'm excited to dig into the details and hope to leave feedback soon. |
nagisa
reviewed
Aug 13, 2015
| ### Create | ||
| `.create(true)` | ||
|
|
||
| Open an existing file, or create a new file if it already exists. |
This comment has been minimized.
This comment has been minimized.
nagisa
reviewed
Aug 13, 2015
| support mandatory file locking, but it is just as broken as advisory. | ||
|
|
||
| For Rust, the sharing mode can be set with a Windows-specific option. Given the | ||
| problems above, i don't expect there to ever be a cross-platform option for file |
This comment has been minimized.
This comment has been minimized.
nagisa
Aug 13, 2015
Contributor
In near future, perhaps not, but I’m pretty sure a way to do it would get implemented in a timely manner should a reason to do so arise.
nagisa
reviewed
Aug 13, 2015
| .cache_hint(enum CacheHint) | ||
| enum CacheHint { | ||
| Normal, |
This comment has been minimized.
This comment has been minimized.
nagisa
Aug 13, 2015
Contributor
Bikeshed: What’s a “normal” cache hint? Perhaps None would be better?
pitdicker
added some commits
Aug 14, 2015
This comment has been minimized.
This comment has been minimized.
|
Sorry for making some more commits to the RFC, I am clearly an amateur... |
alexcrichton
self-assigned this
Aug 19, 2015
This comment has been minimized.
This comment has been minimized.
|
Just a note about an issue I ran into today. Opening a path to a directory as a file has different results on different platforms, and should be documented also. I was only able to test UNIX, but the results on UNIX were:
|
This comment has been minimized.
This comment has been minimized.
ehiggs
commented
Aug 26, 2015
|
The documentation here is pretty extensive. Is it worth mentioning how Also, wouldn't it be better to yield an error if people start mixing flags in broken ways? |
This comment has been minimized.
This comment has been minimized.
|
@withoutboats, @ehiggs thanks for your comments! @withoutboats @ehiggs In this case I think it is best to return an error if |
This comment has been minimized.
This comment has been minimized.
IMO it can be thought about in a way that makes sense:
The fact that |
This comment has been minimized.
This comment has been minimized.
|
@nagisa Yes, |
This comment has been minimized.
This comment has been minimized.
|
It need not be an error, but could be a lint. I'll open an issue over at clippy for now. |
This comment has been minimized.
This comment has been minimized.
|
Would be nice to somehow advance it since the discussion has stalled. Could it be possible to include into schedule of the next libs team meeting/do a FCP? |
This comment has been minimized.
This comment has been minimized.
I realised I never answered your question. I fear I’ve forgotten my original point. Here’s the current thoughts (that may or may not differ from whatever I said earlier): In case where two options are mutually exclusive, it is always possible to encode that in the API by removing the possible intersection point. In case of
However, since we are bound by stability guarantees, I guess simply panicking in the builder finalizer (the |
This comment has been minimized.
This comment has been minimized.
|
Just a heads-up: clippy now contains a nonsensical_open_option lint. |
This comment has been minimized.
This comment has been minimized.
|
I don't see why the exact conflicting-options-behaviour (supercede, one takes priority...) matters as long as it is well documented. Anyway, looks like an amazing API (from my semi-ignorant viewpoint). I'd offer to help with impl/testing (Linux) but it looks like you're way ahead of me. |
alexcrichton
reviewed
Nov 3, 2015
| `.share_mode(DENY_READ | DENY_WRITE | DENY_DELETE)`. | ||
|
|
||
|
|
||
| ## Caching behaviour |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Nov 3, 2015
Member
Could you elaborate a bit on the inclusion of these new options? I would personally expect this to fall under the category of "out of scope for now" in the sense that this should all in theory be possible to implement externally (e.g. using the as-raw-os-handle style traits).
alexcrichton
reviewed
Nov 3, 2015
| os | since version | oldest supported version | ||
| :-------------|:--------------|:------------------------ | ||
| OS X | 10.6 | 10.7? | ||
| Linux | 2.6.23 | 2.6.32 (supported by Rust) |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Nov 3, 2015
Member
Ah unfortunate we actually support back to 2.6.18, but older kernels just ignore O_CLOEXEC so we just pass it unconditionally and then also set cloexec after opening. This is redundant work on modern Unixes, but gets the job done at least!
This comment has been minimized.
This comment has been minimized.
pitdicker
Nov 3, 2015
Author
Contributor
At the time I write this part, O_CLOEXEC was not yet passed, but now it is not really an interesting part of the rfc anymore :)
This comment has been minimized.
This comment has been minimized.
|
Sorry for taking so look to get around to this @pitdicker, but it all looks great to me! It'd be nice to have a concise overview of the OS-specific extension traits in terms of what the APIs would look like, but I think it's also relatively easy to infer to it's not critical. I agree with @nagisa and I'll try to bring this up soon at a libs team meeting to move into FCP. |
This comment has been minimized.
This comment has been minimized.
|
Everyone thanks for the comments and pursuing. Sorry for not doing this I have changed my opinion about 'no access mode set'. It does not really have Also, I have rewritten the caching part of the rfc, put not yet pushed. |
This comment has been minimized.
This comment has been minimized.
|
@llogiq I keep being amazed how much you can lint for! Very nice to see a nonsensical_open_option lint. |
This comment has been minimized.
This comment has been minimized.
|
I'd be fine with no access mode == error, I think we'd definitely be able to expand that in the future to return success if an interesting case came up. I'd also be ok leaving the caching/file locking to a separate RFC, although ensuring there's design space for it is fine to mention (although with a builder-style thing we should be pretty set) |
This comment has been minimized.
This comment has been minimized.
|
@pitdicker We haven't even made a dent in the surface of what can be linted. The Btw. if you see other APIs that have ambiguous or confusing API items, just file a clippy issue, no matter if you think it possible to lint or not. |
This comment has been minimized.
This comment has been minimized.
|
@pitdicker I have no clue who would make use of the Windows-specific share mode. It replaces one set of problems with another, though I guess it would be nice to know writes wouldn't collide (if this could be done cross-platform). Speaking of which, the atomic append operations appear to be limited in length. See here and specifically here. Anywhere from 256 bytes to 4k. Makes it useless for what I wanted to do, but anyway. |
This comment has been minimized.
This comment has been minimized.
|
@dhardy I did some testing for the length of atomic append because of these posts, and did not find a limit. I think they found a limit because that language uses buffered IO or a pipe with a buffer. |
This comment has been minimized.
This comment has been minimized.
|
@pitdicker great news. Sounds like it should be tested on a few different platforms still. |
This comment has been minimized.
This comment has been minimized.
ehiggs
commented
Nov 6, 2015
|
@llogiq, @Pyriphlegethon: that's great news about the lint. My concern about nonsensical flags are basically solved. Thanks! |
This comment has been minimized.
This comment has been minimized.
|
Well, in a perfect world, a lint wouldn't be needed, but when using the type system isn't possible (in this case because of backwards-compatibility), it's the best we can do. |
This comment has been minimized.
This comment has been minimized.
|
|
alexcrichton
added
the
final-comment-period
label
Nov 12, 2015
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this during triage today and the decision was to merge. @pitdicker would you be ok moving the sections about caching and such to alternatives as well? We were thinking that for now we may not want to dive into those domains but it's certainly possible in the future! |
pitdicker
added some commits
Nov 22, 2015
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton Great news! |
This comment has been minimized.
This comment has been minimized.
|
I have a local branch with most of the changes proposed by this rfc, but it is messy and I don't have time to clean it up before the Christmas holidays. If anyone wants to implement it, let me know. Maybe you can use it as a starting point... |
alexcrichton
referenced this pull request
Nov 23, 2015
Closed
Tracking issue for OpenOptions expansion #30014
alexcrichton
merged commit b6b4b4b
into
rust-lang:master
Nov 23, 2015
This comment has been minimized.
This comment has been minimized.
|
Looks good to me, thanks @pitdicker! Feel free to send the PR whenever, and thanks so much again for the RFC! |
pitdicker commentedAug 13, 2015
The options that can be passed to the os when opening a file vary between
systems. And even if the options seem the same or similar, there may be
unexpected corner cases.
This RFC attempts to
systems.
rendered