github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/layer/filestore_windows.go (about)

     1  package layer // import "github.com/demonoid81/moby/layer"
     2  
     3  import (
     4  	"fmt"
     5  	"io/ioutil"
     6  	"os"
     7  	"strings"
     8  )
     9  
    10  // setOS writes the "os" file to the layer filestore
    11  func (fm *fileMetadataTransaction) setOS(os string) error {
    12  	if os == "" {
    13  		return nil
    14  	}
    15  	return fm.ws.WriteFile("os", []byte(os), 0644)
    16  }
    17  
    18  // getOS reads the "os" file from the layer filestore
    19  func (fms *fileMetadataStore) getOS(layer ChainID) (string, error) {
    20  	contentBytes, err := ioutil.ReadFile(fms.getLayerFilename(layer, "os"))
    21  	if err != nil {
    22  		// For backwards compatibility, the os file may not exist. Default to "windows" if missing.
    23  		if os.IsNotExist(err) {
    24  			return "windows", nil
    25  		}
    26  		return "", err
    27  	}
    28  	content := strings.TrimSpace(string(contentBytes))
    29  
    30  	if content != "windows" && content != "linux" {
    31  		return "", fmt.Errorf("invalid operating system value: %s", content)
    32  	}
    33  
    34  	return content, nil
    35  }