Files
linuxkit/pkg/metadata/provider_cdrom.go
Rolf Neugebauer 626f02def2 metadata: Improve logging
Implementing a String() interface for each provider makes it
easier for users to prefix log strings with the provider.

Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
2017-04-12 15:39:08 +01:00

42 lines
870 B
Go

package main
import (
"fmt"
"io/ioutil"
"os"
"path"
)
const (
configFile = "config"
)
// ProviderCDROM is the type implementing the Provider interface for CDROMs
// It looks for a file called 'configFile' in the root
type ProviderCDROM struct {
}
// NewCDROM returns a new ProviderCDROM
func NewCDROM() *ProviderCDROM {
return &ProviderCDROM{}
}
func (p *ProviderCDROM) String() string {
return "CDROM"
}
// Probe checks if the CD has the right file
func (p *ProviderCDROM) Probe() bool {
_, err := os.Stat(path.Join(MountPoint, configFile))
return (!os.IsNotExist(err))
}
// Extract gets both the CDROM specific and generic userdata
func (p *ProviderCDROM) Extract() ([]byte, error) {
data, err := ioutil.ReadFile(path.Join(MountPoint, configFile))
if err != nil {
return nil, fmt.Errorf("CDROM: Error reading file: %s", err)
}
return data, nil
}