build: Don't create empty kernel/cmdline files
If the YAML does not specify a kernel, kernel commandline
or any containers, don't create empty files. Note, an
initrd file is still created if the kernel image contains
CPU ucode.
This only applies to kernel+initrd and tar-kernel-initrd
output formats.
@@ -370,6 +370,7 @@ func outputKernelInitrd(base string, kernel []byte, initrd []byte, cmdline strin
if err := ioutil.WriteFile(base+"-initrd.img", ucode, os.FileMode(0644)); err != nil {
return err
}
+ if len(initrd) != 0 {
f, err := os.OpenFile(base+"-initrd.img", os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
return err
@@ -378,17 +379,25 @@ func outputKernelInitrd(base string, kernel []byte, initrd []byte, cmdline strin
if _, err = f.Write(initrd); err != nil {
return err
}
+ }
} else {
+ if len(initrd) != 0 {
log.Infof(" %s %s %s", base+"-kernel", base+"-initrd.img", base+"-cmdline")
if err := ioutil.WriteFile(base+"-initrd.img", initrd, os.FileMode(0644)); err != nil {
return err
}
}
+ }
+ if len(kernel) != 0 {
if err := ioutil.WriteFile(base+"-kernel", kernel, os.FileMode(0644)); err != nil {
return err
}
+ }
+ if len(cmdline) != 0 {
return ioutil.WriteFile(base+"-cmdline", []byte(cmdline), os.FileMode(0644))
}
+ return nil
+}
func outputKernelInitrdTarball(base string, kernel []byte, initrd []byte, cmdline string, ucode []byte) error {
log.Debugf("output kernel/initrd tarball: %s %s", base, cmdline)
@@ -399,6 +408,7 @@ func outputKernelInitrdTarball(base string, kernel []byte, initrd []byte, cmdlin
}
defer f.Close()
tw := tar.NewWriter(f)
+ if len(kernel) != 0 {
hdr := &tar.Header{
Name: "kernel",
Mode: 0644,
@@ -411,7 +421,9 @@ func outputKernelInitrdTarball(base string, kernel []byte, initrd []byte, cmdlin
if _, err := tw.Write(kernel); err != nil {
return err
}
- hdr = &tar.Header{
+ }
+ if len(initrd) != 0 {
+ hdr := &tar.Header{
Name: "initrd.img",
Mode: 0644,
Size: int64(len(initrd)),
@@ -423,7 +435,9 @@ func outputKernelInitrdTarball(base string, kernel []byte, initrd []byte, cmdlin
if _, err := tw.Write(initrd); err != nil {
return err
}
- hdr = &tar.Header{
+ }
+ if len(cmdline) != 0 {
+ hdr := &tar.Header{
Name: "cmdline",
Mode: 0644,
Size: int64(len(cmdline)),
@@ -435,6 +449,7 @@ func outputKernelInitrdTarball(base string, kernel []byte, initrd []byte, cmdlin
if _, err := tw.Write([]byte(cmdline)); err != nil {
return err
}
+ }
if len(ucode) != 0 {
hdr := &tar.Header{
Name: "ucode.cpio",
