github.com/lacework-dev/go-moby@v20.10.12+incompatible/layer/filestore_windows.go (about) 1 package layer // import "github.com/docker/docker/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 }