Open
Conversation
functionality to other build commands.
iliana
reviewed
May 14, 2024
src/build.rs
Outdated
Comment on lines
+151
to
+158
| pub(crate) fn create_iso(self) -> Result<(std::path::PathBuf, Metadata)> { | ||
| let output_path_arg = self.output_path.clone(); | ||
| let (mut file, temp_path) = if let Some(output_path) = &output_path_arg { | ||
| NamedTempFile::new_in(output_path.parent().context("output path has no parent")?)? | ||
| .into_parts() | ||
| } else { | ||
| NamedTempFile::new()?.into_parts() | ||
| }; |
Collaborator
There was a problem hiding this comment.
This function doesn't return either a NamedTempFile or TempPath, so the output path will be deleted when temp_path is dropped at the end of the function if output_path_arg is None.
To get the behavior you want you might need to have an enum with two variants, a PathBuf and a TempPath.
Collaborator
Author
There was a problem hiding this comment.
Ah, hmm.
What do you think about using std::fs::copy instead of NamedTempFile::persist so it's not consumed and then we have this return the TempPath we created?
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This brings the
output_pathparameter and functionality from thebuildcommand to other build commands, such ascreate-ec2-imageandcreate-oxide-image, which enables me to make use of GitHub Artifact Attestation for the builds I'm doing.In addition to moving
output_pathtobuild::Args, I moved the code that handles creation of the temp and persistent files it into thebuild::create_iso, which seemed more appropriate than leaving it a level up for each of the CLI commands to implement.Also, I bumped the version number because this is a breaking change.