2017-04-25 16:37:29 +00:00
|
|
|
package layer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2017-08-08 19:43:48 +00:00
|
|
|
// SetOS writes the "os" file to the layer filestore
|
|
|
|
func (fm *fileMetadataTransaction) SetOS(os OS) error {
|
|
|
|
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-08-08 19:43:48 +00:00
|
|
|
// GetOS reads the "os" file from the layer filestore
|
|
|
|
func (fms *fileMetadataStore) GetOS(layer ChainID) (OS, error) {
|
|
|
|
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-08 19:43:48 +00:00
|
|
|
return OS(content), nil
|
2017-04-25 16:37:29 +00:00
|
|
|
}
|