2018-02-05 21:05:59 +00:00
|
|
|
package layer // import "github.com/docker/docker/layer"
|
2017-04-25 16:37:29 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2017-11-20 16:33:20 +00:00
|
|
|
// setOS writes the "os" file to the layer filestore
|
|
|
|
func (fm *fileMetadataTransaction) setOS(os string) error {
|
2017-08-08 19:43:48 +00:00
|
|
|
if os == "" {
|
2017-04-25 16:37:29 +00:00
|
|
|
return nil
|
|
|
|
}
|
2017-08-08 19:43:48 +00:00
|
|
|
return fm.ws.WriteFile("os", []byte(os), 0644)
|
2017-04-25 16:37:29 +00:00
|
|
|
}
|
|
|
|
|
2017-11-20 16:33:20 +00:00
|
|
|
// getOS reads the "os" file from the layer filestore
|
|
|
|
func (fms *fileMetadataStore) getOS(layer ChainID) (string, error) {
|
2017-08-08 19:43:48 +00:00
|
|
|
contentBytes, err := ioutil.ReadFile(fms.getLayerFilename(layer, "os"))
|
2017-04-25 16:37:29 +00:00
|
|
|
if err != nil {
|
2017-08-08 19:43:48 +00:00
|
|
|
// For backwards compatibility, the os file may not exist. Default to "windows" if missing.
|
2017-04-25 16:37:29 +00:00
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return "windows", nil
|
|
|
|
}
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
content := strings.TrimSpace(string(contentBytes))
|
|
|
|
|
|
|
|
if content != "windows" && content != "linux" {
|
2017-08-08 19:43:48 +00:00
|
|
|
return "", fmt.Errorf("invalid operating system value: %s", content)
|
2017-04-25 16:37:29 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 18:48:16 +00:00
|
|
|
return content, nil
|
2017-04-25 16:37:29 +00:00
|
|
|
}
|