post-processor/vagrant: nitpick format
This commit is contained in:
parent
701b867a95
commit
012b534873
|
@ -111,48 +111,6 @@ func DirToBox(dst, dir string, ui packer.Ui) error {
|
||||||
return filepath.Walk(dir, tarWalk)
|
return filepath.Walk(dir, tarWalk)
|
||||||
}
|
}
|
||||||
|
|
||||||
func OvaToDir(dir, src string) error {
|
|
||||||
log.Printf("Turning ova to dir: %s => %s", src, dir)
|
|
||||||
srcF, err := os.Open(src)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer srcF.Close()
|
|
||||||
|
|
||||||
tarReader := tar.NewReader(srcF)
|
|
||||||
|
|
||||||
for {
|
|
||||||
|
|
||||||
hdr, err := tarReader.Next()
|
|
||||||
if hdr == nil || err == io.EOF {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
info := hdr.FileInfo()
|
|
||||||
|
|
||||||
// Shouldn't be any directories, skip them
|
|
||||||
if info.IsDir() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
path := filepath.Join(dir, info.Name())
|
|
||||||
output, err := os.Create(path)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer output.Close()
|
|
||||||
|
|
||||||
os.Chmod(path, info.Mode())
|
|
||||||
os.Chtimes(path, hdr.AccessTime, hdr.ModTime)
|
|
||||||
|
|
||||||
if _, err := io.Copy(output, tarReader); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// WriteMetadata writes the "metadata.json" file for a Vagrant box.
|
// WriteMetadata writes the "metadata.json" file for a Vagrant box.
|
||||||
func WriteMetadata(dir string, contents interface{}) error {
|
func WriteMetadata(dir string, contents interface{}) error {
|
||||||
f, err := os.Create(filepath.Join(dir, "metadata.json"))
|
f, err := os.Create(filepath.Join(dir, "metadata.json"))
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package vagrant
|
package vagrant
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"archive/tar"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mitchellh/packer/common"
|
"github.com/mitchellh/packer/common"
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
@ -85,14 +87,16 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac
|
||||||
|
|
||||||
// Copy all of the original contents into the temporary directory
|
// Copy all of the original contents into the temporary directory
|
||||||
for _, path := range artifact.Files() {
|
for _, path := range artifact.Files() {
|
||||||
ui.Message(fmt.Sprintf("Copying: %s", path))
|
|
||||||
|
|
||||||
|
// We treat OVA files specially, we unpack those into the temporary
|
||||||
|
// directory so we can get the resulting disk and OVF.
|
||||||
if extension := filepath.Ext(path); extension == ".ova" {
|
if extension := filepath.Ext(path); extension == ".ova" {
|
||||||
log.Printf("File is an OVA: %s", path)
|
ui.Message(fmt.Sprintf("Unpacking OVA: %s", path))
|
||||||
if err := OvaToDir(dir, filepath.Base(path)); err != nil {
|
if err := DecompressOva(dir, filepath.Base(path)); err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
ui.Message(fmt.Sprintf("Copying: %s", path))
|
||||||
dstPath := filepath.Join(dir, filepath.Base(path))
|
dstPath := filepath.Join(dir, filepath.Base(path))
|
||||||
if err := CopyContents(dstPath, path); err != nil {
|
if err := CopyContents(dstPath, path); err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
|
@ -215,6 +219,53 @@ func (p *VBoxBoxPostProcessor) findBaseMacAddress(dir string) (string, error) {
|
||||||
return string(matches[1]), nil
|
return string(matches[1]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DecompressOva takes an ova file and decompresses it into the target
|
||||||
|
// directory.
|
||||||
|
func DecompressOva(dir, src string) error {
|
||||||
|
log.Printf("Turning ova to dir: %s => %s", src, dir)
|
||||||
|
srcF, err := os.Open(src)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer srcF.Close()
|
||||||
|
|
||||||
|
tarReader := tar.NewReader(srcF)
|
||||||
|
for {
|
||||||
|
hdr, err := tarReader.Next()
|
||||||
|
if hdr == nil || err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
info := hdr.FileInfo()
|
||||||
|
|
||||||
|
// Shouldn't be any directories, skip them
|
||||||
|
if info.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// We wrap this in an anonymous function so that the defers
|
||||||
|
// inside are handled more quickly so we can give up file handles.
|
||||||
|
err = func() error {
|
||||||
|
path := filepath.Join(dir, info.Name())
|
||||||
|
output, err := os.Create(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer output.Close()
|
||||||
|
|
||||||
|
os.Chmod(path, info.Mode())
|
||||||
|
os.Chtimes(path, hdr.AccessTime, hdr.ModTime)
|
||||||
|
_, err = io.Copy(output, tarReader)
|
||||||
|
return err
|
||||||
|
}()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var defaultVBoxVagrantfile = `
|
var defaultVBoxVagrantfile = `
|
||||||
Vagrant.configure("2") do |config|
|
Vagrant.configure("2") do |config|
|
||||||
config.vm.base_mac = "{{ .BaseMacAddress }}"
|
config.vm.base_mac = "{{ .BaseMacAddress }}"
|
||||||
|
|
Loading…
Reference in New Issue