Skip to content

Commit 7fcc366

Browse files
committed
generate: Don't serialize Spec.Linux as an empty JSON object
The "does the marshaled JSON look like '{}'?" check is a pretty cheap trick, but it was the easiest way I could think of for "is there anything useful in here?". Signed-off-by: W. Trevor King <[email protected]>
1 parent 96609ba commit 7fcc366

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

generate/generate.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,16 @@ func (g *Generator) Spec() *rspec.Spec {
188188

189189
// Save writes the spec into w.
190190
func (g *Generator) Save(w io.Writer) error {
191+
if g.spec.Linux != nil {
192+
buf, err := json.Marshal(g.spec.Linux)
193+
if err != nil {
194+
return err
195+
}
196+
if string(buf) == "{}" {
197+
g.spec.Linux = nil
198+
}
199+
}
200+
191201
data, err := json.MarshalIndent(g.spec, "", "\t")
192202
if err != nil {
193203
return err

0 commit comments

Comments
 (0)