buidler/virtualbox,vmware: only stat if not force

/cc @jasonberanek - Swapped this because why even bother doing a stat
if we're forcing anyways.
This commit is contained in:
Mitchell Hashimoto 2013-07-13 14:47:08 +09:00
parent 276428a330
commit 245deaf599
3 changed files with 11 additions and 7 deletions

View File

@ -219,9 +219,11 @@ func (b *Builder) Prepare(raws ...interface{}) error {
}
}
if _, err := os.Stat(b.config.OutputDir); err == nil {
if !b.config.PackerForce {
errs = append(errs, errors.New("Output directory already exists. It must not exist."))
if !b.config.PackerForce {
if _, err := os.Stat(b.config.OutputDir); err == nil {
errs = append(
errs,
errors.New("Output directory already exists. It must not exist."))
}
}

View File

@ -175,9 +175,11 @@ func (b *Builder) Prepare(raws ...interface{}) error {
}
}
if _, err := os.Stat(b.config.OutputDir); err == nil {
if !b.config.PackerForce {
errs = append(errs, errors.New("Output directory already exists. It must not exist."))
if !b.config.PackerForce {
if _, err := os.Stat(b.config.OutputDir); err == nil {
errs = append(
errs,
errors.New("Output directory already exists. It must not exist."))
}
}

View File

@ -15,7 +15,7 @@ func (stepPrepareOutputDir) Run(state map[string]interface{}) multistep.StepActi
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