Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
aeb395fe
Commit
aeb395fe
authored
Aug 23, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
post-processor/vagrant: nitpick format
parent
cc0c4888
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
45 deletions
+54
-45
post-processor/vagrant/util.go
post-processor/vagrant/util.go
+0
-42
post-processor/vagrant/virtualbox.go
post-processor/vagrant/virtualbox.go
+54
-3
No files found.
post-processor/vagrant/util.go
View file @
aeb395fe
...
...
@@ -111,48 +111,6 @@ func DirToBox(dst, dir string, ui packer.Ui) error {
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.
func
WriteMetadata
(
dir
string
,
contents
interface
{})
error
{
f
,
err
:=
os
.
Create
(
filepath
.
Join
(
dir
,
"metadata.json"
))
...
...
post-processor/vagrant/virtualbox.go
View file @
aeb395fe
package
vagrant
import
(
"archive/tar"
"errors"
"fmt"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"io"
"io/ioutil"
"log"
"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
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"
{
log
.
Printf
(
"File is an OVA: %s"
,
path
)
if
err
:=
OvaToDir
(
dir
,
filepath
.
Base
(
path
));
err
!=
nil
{
ui
.
Message
(
fmt
.
Sprintf
(
"Unpacking OVA: %s"
,
path
)
)
if
err
:=
DecompressOva
(
dir
,
filepath
.
Base
(
path
));
err
!=
nil
{
return
nil
,
false
,
err
}
}
else
{
ui
.
Message
(
fmt
.
Sprintf
(
"Copying: %s"
,
path
))
dstPath
:=
filepath
.
Join
(
dir
,
filepath
.
Base
(
path
))
if
err
:=
CopyContents
(
dstPath
,
path
);
err
!=
nil
{
return
nil
,
false
,
err
...
...
@@ -215,6 +219,53 @@ func (p *VBoxBoxPostProcessor) findBaseMacAddress(dir string) (string, error) {
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
=
`
Vagrant.configure("2") do |config|
config.vm.base_mac = "{{ .BaseMacAddress }}"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment