mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-18 17:01:07 +00:00
Consolidate metadata ISO writing into a single function
Used by both `metadata create` and the hyperkit runner. Signed-off-by: Ian Campbell <ian.campbell@docker.com>
This commit is contained in:
parent
36eaa44d7e
commit
c1ce8b4688
@ -9,6 +9,17 @@ import (
|
||||
"github.com/rneugeba/iso9660wrap"
|
||||
)
|
||||
|
||||
// WriteMetadataISO writes a metadata ISO file in a format usable by pkg/metadata
|
||||
func WriteMetadataISO(path string, content []byte) error {
|
||||
outfh, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer outfh.Close()
|
||||
|
||||
return iso9660wrap.WriteBuffer(outfh, content, "config")
|
||||
}
|
||||
|
||||
func metadataCreateUsage() {
|
||||
invoked := filepath.Base(os.Args[0])
|
||||
fmt.Printf("USAGE: %s metadata create [file.iso] [metadata]\n\n", invoked)
|
||||
@ -32,15 +43,8 @@ func metadataCreate(args []string) {
|
||||
isoImage := args[0]
|
||||
metadata := args[1]
|
||||
|
||||
outfh, err := os.OpenFile(isoImage, os.O_CREATE|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
log.Fatal("Cannot create user data ISOs", "err", err)
|
||||
}
|
||||
defer outfh.Close()
|
||||
|
||||
err = iso9660wrap.WriteBuffer(outfh, []byte(metadata), "config")
|
||||
if err != nil {
|
||||
log.Fatal("Cannot write user data ISO", "err", err)
|
||||
if err := WriteMetadataISO(isoImage, []byte(metadata)); err != nil {
|
||||
log.Fatal("Failed to write user data ISO: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,6 @@ import (
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/moby/hyperkit/go"
|
||||
"github.com/rneugeba/iso9660wrap"
|
||||
"github.com/satori/go.uuid"
|
||||
)
|
||||
|
||||
@ -56,16 +55,8 @@ func runHyperKit(args []string) {
|
||||
}
|
||||
}
|
||||
isoPath = prefix + "-data.iso"
|
||||
outfh, err := os.OpenFile(isoPath, os.O_CREATE|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
log.Fatalf("Cannot create user data ISO: %v", err)
|
||||
}
|
||||
err = iso9660wrap.WriteBuffer(outfh, d, "config")
|
||||
if err != nil {
|
||||
log.Fatalf("Cannot write user data ISO: %v", err)
|
||||
}
|
||||
if err = outfh.Close(); err != nil {
|
||||
log.Fatalf("Cannot close output ISO: %v", err)
|
||||
if err := WriteMetadataISO(isoPath, d); err != nil {
|
||||
log.Fatalf("Cannot write user data ISO: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user