mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
fc21bf280b
Signed-off-by: John Howard <jhoward@microsoft.com>
35 lines
919 B
Go
35 lines
919 B
Go
package layer
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
// SetPlatform writes the "platform" file to the layer filestore
|
|
func (fm *fileMetadataTransaction) SetPlatform(platform Platform) error {
|
|
if platform == "" {
|
|
return nil
|
|
}
|
|
return fm.ws.WriteFile("platform", []byte(platform), 0644)
|
|
}
|
|
|
|
// GetPlatform reads the "platform" file from the layer filestore
|
|
func (fms *fileMetadataStore) GetPlatform(layer ChainID) (Platform, error) {
|
|
contentBytes, err := ioutil.ReadFile(fms.getLayerFilename(layer, "platform"))
|
|
if err != nil {
|
|
// For backwards compatibility, the platform file may not exist. Default to "windows" if missing.
|
|
if os.IsNotExist(err) {
|
|
return "windows", nil
|
|
}
|
|
return "", err
|
|
}
|
|
content := strings.TrimSpace(string(contentBytes))
|
|
|
|
if content != "windows" && content != "linux" {
|
|
return "", fmt.Errorf("invalid platform value: %s", content)
|
|
}
|
|
|
|
return Platform(content), nil
|
|
}
|