Only create qemu runner state dir if it is going to be used.

Signed-off-by: Ian Campbell <ian.campbell@docker.com>
This commit is contained in:
Ian Campbell 2017-06-13 17:21:52 +01:00
parent 58d61d0846
commit e2eb17ef6c

View File

@ -118,8 +118,12 @@ func runQemu(args []string) {
if *state == "" { if *state == "" {
*state = prefix + "-state" *state = prefix + "-state"
} }
if err := os.MkdirAll(*state, 0755); err != nil { var mkstate func()
log.Fatalf("Could not create state directory: %v", err) mkstate = func() {
if err := os.MkdirAll(*state, 0755); err != nil {
log.Fatalf("Could not create state directory: %v", err)
}
mkstate = func() {}
} }
isoPath := "" isoPath := ""
@ -133,6 +137,7 @@ func runQemu(args []string) {
log.Fatalf("Cannot read user data: %v", err) log.Fatalf("Cannot read user data: %v", err)
} }
} }
mkstate()
isoPath = filepath.Join(*state, "data.iso") isoPath = filepath.Join(*state, "data.iso")
if err := WriteMetadataISO(isoPath, d); err != nil { if err := WriteMetadataISO(isoPath, d); err != nil {
log.Fatalf("Cannot write user data ISO: %v", err) log.Fatalf("Cannot write user data ISO: %v", err)
@ -148,6 +153,7 @@ func runQemu(args []string) {
d.Format = "qcow2" d.Format = "qcow2"
} }
if d.Size != 0 && d.Path == "" { if d.Size != 0 && d.Path == "" {
mkstate()
d.Path = filepath.Join(*state, "disk"+id+".img") d.Path = filepath.Join(*state, "disk"+id+".img")
} }
if d.Path == "" { if d.Path == "" {