-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
bootstrap: write texts to a .tmp file first for atomicity #51816
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
r? @kennytm |
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.
r=me with one nit.
src/bootstrap/configure.py
Outdated
@@ -428,11 +429,18 @@ def configure_section(lines, config): | |||
else: | |||
configure_section(sections[section_key], section_config) | |||
|
|||
@contextlib.contextmanager | |||
def output(filepath): |
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.
configure
imports bootstrap
, so just reuse bootstrap.output
and remove this def.
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.
Great point, fixed it accordingly.
de9d173
to
9eb3d5a
Compare
Hold on, I have a concern.
This means it can't really overwrite a file on Windows. Calling
On Python 3.3+ we could use Could you perform these fallback measures?
|
Crap, this thing totally slipped my mind, I've been away from Win32 these days... I've pushed a better Win32 support as you suggested, but I'm not sure if the goal of this patch worths the code length anymore. This is a WIP as I'm still confirming |
Could the file be removed, ignoring errors, prior to creation? I think that'd help avoid the platform-specific goop? |
Ping from triage, @nodakai we haven't heard from you for a while, will you have time to look into this PR in near future? |
Just pushed smaller fixes; waiting for the CI... |
Since we aren't really going for speed here, could remove + write always be used? It seems like that would be the most clear with no version or os checks |
If you are using a hard-linked file as your config.toml, this change will affect the way other instances of the file is modified. The original version would modify all other instances whereas the new version will leave others unchanged, reducing the ref count by one. Signed-off-by: NODA, Kai <[email protected]>
This is a tricky operation to implement on Win32; see https://ci.appveyor.com/project/nodakai/python-win-behavior Signed-off-by: NODA, Kai <[email protected]>
@alexcrichton Indeed there's little to be gained from sticking to the really-atomic overwrite. Now we have just two cases. |
The aspect of windows holding a file open can probably be skipped as well, right? This is just a configuration file and doesn't really have a lot of windows programs holding it open I think? |
@alexcrichton Your text editor could be one, when you are watching what the generated file looks like? |
Do text editors really keep files open? I'm under the impression they only hold it briefly open while opening and closing files |
At least for |
Eh I'll leave this up to you @kennytm |
@bors r+ rollup |
📌 Commit 97d0bc3 has been approved by |
bootstrap: write texts to a .tmp file first for atomicity If you are using a hard-linked file as your config.toml, this change will affect the way other instances of the file is modified. The original version would modify all other instances whereas the new version will leave others unchanged, reducing the ref count by one.
Rollup of 9 pull requests Successful merges: - #51816 (bootstrap: write texts to a .tmp file first for atomicity) - #51912 (impl Clone for Box<CStr>, Box<OsStr>, Box<Path>) - #52164 (use proper footnote syntax for references) - #52220 (Deny bare trait objects in `src/bootstrap`) - #52276 (rustc: Verify #[proc_macro] is only a word) - #52277 (Uncapitalize "If") - #52287 (Deny bare trait objects in src/librustc_resolve) - #52295 (Deny bare trait objects in src/libsyntax_ext) - #52298 (make reference to dirs crate clickable in terminals) Failed merges: r? @ghost
If you are using a hard-linked file as your config.toml, this change will affect the way other instances of the file is modified.
The original version would modify all other instances whereas the new version will leave others unchanged, reducing the ref count by one.