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
70af2161
Commit
70af2161
authored
Jun 15, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2233 from mitchellh/b-output-dir
builder/virtualbox,vmware: validate output dir in step
parents
ac367c2b
d8518981
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
41 additions
and
87 deletions
+41
-87
builder/virtualbox/common/output_config.go
builder/virtualbox/common/output_config.go
+1
-10
builder/virtualbox/common/output_config_test.go
builder/virtualbox/common/output_config_test.go
+1
-21
builder/virtualbox/common/step_output_dir.go
builder/virtualbox/common/step_output_dir.go
+10
-1
builder/virtualbox/common/step_output_dir_test.go
builder/virtualbox/common/step_output_dir_test.go
+24
-0
builder/vmware/common/output_config.go
builder/vmware/common/output_config.go
+1
-10
builder/vmware/common/output_config_test.go
builder/vmware/common/output_config_test.go
+2
-43
builder/vmware/iso/builder_test.go
builder/vmware/iso/builder_test.go
+2
-2
No files found.
builder/virtualbox/common/output_config.go
View file @
70af2161
...
@@ -2,7 +2,6 @@ package common
...
@@ -2,7 +2,6 @@ package common
import
(
import
(
"fmt"
"fmt"
"os"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/template/interpolate"
"github.com/mitchellh/packer/template/interpolate"
...
@@ -17,13 +16,5 @@ func (c *OutputConfig) Prepare(ctx *interpolate.Context, pc *common.PackerConfig
...
@@ -17,13 +16,5 @@ func (c *OutputConfig) Prepare(ctx *interpolate.Context, pc *common.PackerConfig
c
.
OutputDir
=
fmt
.
Sprintf
(
"output-%s"
,
pc
.
PackerBuildName
)
c
.
OutputDir
=
fmt
.
Sprintf
(
"output-%s"
,
pc
.
PackerBuildName
)
}
}
var
errs
[]
error
return
nil
if
!
pc
.
PackerForce
{
if
_
,
err
:=
os
.
Stat
(
c
.
OutputDir
);
err
==
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Output directory '%s' already exists. It must not exist."
,
c
.
OutputDir
))
}
}
return
errs
}
}
builder/virtualbox/common/output_config_test.go
View file @
70af2161
...
@@ -39,27 +39,7 @@ func TestOutputConfigPrepare_exists(t *testing.T) {
...
@@ -39,27 +39,7 @@ func TestOutputConfigPrepare_exists(t *testing.T) {
PackerForce
:
false
,
PackerForce
:
false
,
}
}
errs
:=
c
.
Prepare
(
testConfigTemplate
(
t
),
pc
)
errs
:=
c
.
Prepare
(
testConfigTemplate
(
t
),
pc
)
if
len
(
errs
)
==
0
{
if
len
(
errs
)
!=
0
{
t
.
Fatal
(
"should have errors"
)
}
}
func
TestOutputConfigPrepare_forceExists
(
t
*
testing
.
T
)
{
td
,
err
:=
ioutil
.
TempDir
(
""
,
"packer"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
defer
os
.
RemoveAll
(
td
)
c
:=
new
(
OutputConfig
)
c
.
OutputDir
=
td
pc
:=
&
common
.
PackerConfig
{
PackerBuildName
:
"foo"
,
PackerForce
:
true
,
}
errs
:=
c
.
Prepare
(
testConfigTemplate
(
t
),
pc
)
if
len
(
errs
)
>
0
{
t
.
Fatal
(
"should not have errors"
)
t
.
Fatal
(
"should not have errors"
)
}
}
}
}
builder/virtualbox/common/step_output_dir.go
View file @
70af2161
...
@@ -22,7 +22,16 @@ type StepOutputDir struct {
...
@@ -22,7 +22,16 @@ type StepOutputDir struct {
func
(
s
*
StepOutputDir
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
func
(
s
*
StepOutputDir
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
if
_
,
err
:=
os
.
Stat
(
s
.
Path
);
err
==
nil
&&
s
.
Force
{
if
_
,
err
:=
os
.
Stat
(
s
.
Path
);
err
==
nil
{
if
!
s
.
Force
{
err
:=
fmt
.
Errorf
(
"Output directory exists: %s
\n\n
"
+
"Use the force flag to delete it prior to building."
,
s
.
Path
)
state
.
Put
(
"error"
,
err
)
return
multistep
.
ActionHalt
}
ui
.
Say
(
"Deleting previous output directory..."
)
ui
.
Say
(
"Deleting previous output directory..."
)
os
.
RemoveAll
(
s
.
Path
)
os
.
RemoveAll
(
s
.
Path
)
}
}
...
...
builder/virtualbox/common/step_output_dir_test.go
View file @
70af2161
...
@@ -45,6 +45,30 @@ func TestStepOutputDir(t *testing.T) {
...
@@ -45,6 +45,30 @@ func TestStepOutputDir(t *testing.T) {
}
}
}
}
func
TestStepOutputDir_exists
(
t
*
testing
.
T
)
{
state
:=
testState
(
t
)
step
:=
testStepOutputDir
(
t
)
// Make the dir
if
err
:=
os
.
MkdirAll
(
step
.
Path
,
0755
);
err
!=
nil
{
t
.
Fatalf
(
"bad: %s"
,
err
)
}
// Test the run
if
action
:=
step
.
Run
(
state
);
action
!=
multistep
.
ActionHalt
{
t
.
Fatalf
(
"bad action: %#v"
,
action
)
}
if
_
,
ok
:=
state
.
GetOk
(
"error"
);
!
ok
{
t
.
Fatal
(
"should have error"
)
}
// Test the cleanup
step
.
Cleanup
(
state
)
if
_
,
err
:=
os
.
Stat
(
step
.
Path
);
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
}
func
TestStepOutputDir_cancelled
(
t
*
testing
.
T
)
{
func
TestStepOutputDir_cancelled
(
t
*
testing
.
T
)
{
state
:=
testState
(
t
)
state
:=
testState
(
t
)
step
:=
testStepOutputDir
(
t
)
step
:=
testStepOutputDir
(
t
)
...
...
builder/vmware/common/output_config.go
View file @
70af2161
...
@@ -2,7 +2,6 @@ package common
...
@@ -2,7 +2,6 @@ package common
import
(
import
(
"fmt"
"fmt"
"os"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/template/interpolate"
"github.com/mitchellh/packer/template/interpolate"
...
@@ -17,13 +16,5 @@ func (c *OutputConfig) Prepare(ctx *interpolate.Context, pc *common.PackerConfig
...
@@ -17,13 +16,5 @@ func (c *OutputConfig) Prepare(ctx *interpolate.Context, pc *common.PackerConfig
c
.
OutputDir
=
fmt
.
Sprintf
(
"output-%s"
,
pc
.
PackerBuildName
)
c
.
OutputDir
=
fmt
.
Sprintf
(
"output-%s"
,
pc
.
PackerBuildName
)
}
}
var
errs
[]
error
return
nil
if
!
pc
.
PackerForce
{
if
_
,
err
:=
os
.
Stat
(
c
.
OutputDir
);
err
==
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Output directory '%s' already exists. It must not exist."
,
c
.
OutputDir
))
}
}
return
errs
}
}
builder/vmware/common/output_config_test.go
View file @
70af2161
package
common
package
common
import
(
import
(
"github.com/mitchellh/packer/common"
"io/ioutil"
"os"
"testing"
"testing"
"github.com/mitchellh/packer/common"
)
)
func
TestOutputConfigPrepare
(
t
*
testing
.
T
)
{
func
TestOutputConfigPrepare
(
t
*
testing
.
T
)
{
...
@@ -23,43 +22,3 @@ func TestOutputConfigPrepare(t *testing.T) {
...
@@ -23,43 +22,3 @@ func TestOutputConfigPrepare(t *testing.T) {
t
.
Fatal
(
"should have output dir"
)
t
.
Fatal
(
"should have output dir"
)
}
}
}
}
func
TestOutputConfigPrepare_exists
(
t
*
testing
.
T
)
{
td
,
err
:=
ioutil
.
TempDir
(
""
,
"packer"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
defer
os
.
RemoveAll
(
td
)
c
:=
new
(
OutputConfig
)
c
.
OutputDir
=
td
pc
:=
&
common
.
PackerConfig
{
PackerBuildName
:
"foo"
,
PackerForce
:
false
,
}
errs
:=
c
.
Prepare
(
testConfigTemplate
(
t
),
pc
)
if
len
(
errs
)
==
0
{
t
.
Fatal
(
"should have errors"
)
}
}
func
TestOutputConfigPrepare_forceExists
(
t
*
testing
.
T
)
{
td
,
err
:=
ioutil
.
TempDir
(
""
,
"packer"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
defer
os
.
RemoveAll
(
td
)
c
:=
new
(
OutputConfig
)
c
.
OutputDir
=
td
pc
:=
&
common
.
PackerConfig
{
PackerBuildName
:
"foo"
,
PackerForce
:
true
,
}
errs
:=
c
.
Prepare
(
testConfigTemplate
(
t
),
pc
)
if
len
(
errs
)
>
0
{
t
.
Fatal
(
"should not have errors"
)
}
}
builder/vmware/iso/builder_test.go
View file @
70af2161
...
@@ -349,8 +349,8 @@ func TestBuilderPrepare_OutputDir(t *testing.T) {
...
@@ -349,8 +349,8 @@ func TestBuilderPrepare_OutputDir(t *testing.T) {
if
len
(
warns
)
>
0
{
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
}
if
err
=
=
nil
{
if
err
!
=
nil
{
t
.
Fatal
(
"should have error"
)
t
.
Fatal
f
(
"err: %s"
,
err
)
}
}
// Test with a good one
// Test with a good one
...
...
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