-
Notifications
You must be signed in to change notification settings - Fork 467
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
Eagerly close tempfile to fix #1082 #1087
Conversation
src/tool.rs
Outdated
@@ -134,6 +134,9 @@ impl Tool { | |||
})?; | |||
tmp.file() | |||
.write_all(include_bytes!("detect_compiler_family.c"))?; | |||
// Close the file handle *now*, otherwise the compiler may fail to open it on Windows | |||
// (#1082). The file stays on disk and its path remains valid until `tmp` is dropped. | |||
tmp.close(); |
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.
Let's also do a tmp.file().flush()?;
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.
That would call the Write::flush
method, which for File
is a no-op on all mainstream platforms including all that cc supports right now: Windows, Unix, and wasi. If you intend the call as precaution against adding a BufWriter
or something in the future, sure, I can add it. However, if you want to surface I/O errors that would otherwise be detected while closing the file and ignored by dropping, we'll need File::sync_all
as discussed in File
's documentation. Which option do you prefer?
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.
Thanks for investigating this, I'd like file.flush()?;
and file.sync_data()?;
to be called.
I don't think we need file.sync_metadata()?;
, since it's a tempfile.
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.
Done.
src/tempfile.rs
Outdated
@@ -72,13 +72,17 @@ impl NamedTempfile { | |||
pub(super) fn file(&self) -> &File { |
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.
Let's change this method, to fn take_file() -> Option<File>
, so we don't need the close()
method
Thank you! Just two suggestions I'd want you to change |
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.
Thank you!
Fixed #1082