MCPcopy Create free account
hub / github.com/linuxkit/linuxkit / CreateMetadataISO

Function CreateMetadataISO

src/cmd/linuxkit/util.go:295–319  ·  view source on GitHub ↗

CreateMetadataISO writes the provided meta data to an iso file in the given state directory

(state, data string, dataPath string)

Source from the content-addressed store, hash-verified

293
294// CreateMetadataISO writes the provided meta data to an iso file in the given state directory
295func CreateMetadataISO(state, data string, dataPath string) ([]string, error) {
296 var d []byte
297
298 // if we have neither data nor dataPath, nothing to return
299 switch {
300 case data != "" && dataPath != "":
301 return nil, fmt.Errorf("cannot specify options for both data and dataPath")
302 case data == "" && dataPath == "":
303 return []string{}, nil
304 case data != "":
305 d = []byte(data)
306 case dataPath != "":
307 var err error
308 d, err = os.ReadFile(dataPath)
309 if err != nil {
310 return nil, fmt.Errorf("cannot read user data from path %s: %v", dataPath, err)
311 }
312 }
313
314 isoPath := filepath.Join(state, "data.iso")
315 if err := WriteMetadataISO(isoPath, d); err != nil {
316 return nil, fmt.Errorf("cannot write user data ISO: %v", err)
317 }
318 return []string{isoPath}, nil
319}

Callers 3

runHyperkitCmdFunction · 0.85
runQEMUCmdFunction · 0.85

Calls 1

WriteMetadataISOFunction · 0.85

Tested by

no test coverage detected