Remove output directory in a step when "-force" flag step [GH-178]

This commit is contained in:
Jason A. Beranek 2013-07-12 21:23:00 -05:00
parent 39ec791bb2
commit 442c5e3e3b
4 changed files with 14 additions and 8 deletions

View File

@ -220,10 +220,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
}
if _, err := os.Stat(b.config.OutputDir); err == nil {
if b.config.PackerForce {
log.Printf("Build forced, removing existing output directory: %s", string(b.config.OutputDir))
os.RemoveAll(b.config.OutputDir)
} else {
if !b.config.PackerForce {
errs = append(errs, errors.New("Output directory already exists. It must not exist."))
}
}

View File

@ -10,6 +10,12 @@ type stepPrepareOutputDir struct{}
func (stepPrepareOutputDir) Run(state map[string]interface{}) multistep.StepAction {
config := state["config"].(*config)
ui := state["ui"].(packer.Ui)
if _, err := os.Stat(config.OutputDir); err == nil && config.PackerForce {
ui.Say("Deleting previous output directory...")
os.RemoveAll(config.OutputDir)
}
if err := os.MkdirAll(config.OutputDir, 0755); err != nil {
state["error"] = err

View File

@ -176,10 +176,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
}
if _, err := os.Stat(b.config.OutputDir); err == nil {
if b.config.PackerForce {
log.Printf("Build forced, removing existing output directory: %s", string(b.config.OutputDir))
os.RemoveAll(b.config.OutputDir)
} else {
if !b.config.PackerForce {
errs = append(errs, errors.New("Output directory already exists. It must not exist."))
}
}

View File

@ -10,6 +10,12 @@ type stepPrepareOutputDir struct{}
func (stepPrepareOutputDir) Run(state map[string]interface{}) multistep.StepAction {
config := state["config"].(*config)
ui := state["ui"].(packer.Ui)
if _, err := os.Stat(config.OutputDir); err == nil && config.PackerForce {
ui.Say("Deleting previous output directory...")
os.RemoveAll(config.OutputDir)
}
if err := os.MkdirAll(config.OutputDir, 0755); err != nil {
state["error"] = err