mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-10-26 16:58:33 +00:00
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>
42 lines
870 B
Go
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
|
|
}
|