fix post-processor for windows#76
Merged
lbajolet-hashicorp merged 2 commits intohashicorp:mainfrom Jan 9, 2023
Merged
Conversation
Contributor
lbajolet-hashicorp
left a comment
There was a problem hiding this comment.
The fix looks good to me, I think we can use filepath.Base to ensure the full base name is really the name of the disk. This would avoid a potential problem if we have a path that results in something with a suffix that matches, but with an extra prefix.
Other than that, good catch!
post-processor/vagrant/libvirt.go
Outdated
| // Copy the disk image into the temporary directory (as box.img) | ||
| for _, path := range artifact.Files() { | ||
| if strings.HasSuffix(path, "/"+diskName) { | ||
| if strings.HasSuffix(path, diskName) { |
Contributor
There was a problem hiding this comment.
I wonder if we could use filename.Base here instead of HasSuffix? Since we're expecting the name of the disk to be the last part of the path, we can use this and do an equality check on that.
Suggested change
| if strings.HasSuffix(path, diskName) { | |
| if filepath.Base(path) == diskName { |
Contributor
Author
There was a problem hiding this comment.
Good suggestion. I tried it out and made another commit.
lbajolet-hashicorp
approved these changes
Jan 9, 2023
Contributor
lbajolet-hashicorp
left a comment
There was a problem hiding this comment.
LGTM, thanks for the fix!
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.
I'm building a ubuntu 22.04 vagrant box for libvirt provider. The packer config is the one from https://github.com/lavabit/robox/blob/master/generic-libvirt.json.
This works fine when building on a linux host (which is probably the most common case). However, when building on a windows host this plugin fails to include the qcow2 image (renamed to box.img) in the box. I'm using Stefan Weil's QEMU for Windows distribution, which is rather slow, but it does produce a valid qcow2 image.
I've traced this down to be a problem with "/" that actually is a "\" when doing the build on windows.
My fix is rather optimistic and simply removes the slash for the suffix test.
I'm using packer v1.8.5