layer/filestore_windows.go
fc21bf28
 package layer
 
 import (
 	"fmt"
 	"io/ioutil"
 	"os"
 	"strings"
 )
 
0cba7740
 // setOS writes the "os" file to the layer filestore
 func (fm *fileMetadataTransaction) setOS(os string) error {
0380fbff
 	if os == "" {
fc21bf28
 		return nil
 	}
0380fbff
 	return fm.ws.WriteFile("os", []byte(os), 0644)
fc21bf28
 }
 
0cba7740
 // getOS reads the "os" file from the layer filestore
 func (fms *fileMetadataStore) getOS(layer ChainID) (string, error) {
0380fbff
 	contentBytes, err := ioutil.ReadFile(fms.getLayerFilename(layer, "os"))
fc21bf28
 	if err != nil {
0380fbff
 		// For backwards compatibility, the os file may not exist. Default to "windows" if missing.
fc21bf28
 		if os.IsNotExist(err) {
 			return "windows", nil
 		}
 		return "", err
 	}
 	content := strings.TrimSpace(string(contentBytes))
 
 	if content != "windows" && content != "linux" {
0380fbff
 		return "", fmt.Errorf("invalid operating system value: %s", content)
fc21bf28
 	}
 
ce8e529e
 	return content, nil
fc21bf28
 }