github.com/xdlianrong208/docker-ce-comments@v17.12.1-ce-rc2+incompatible/components/engine/layer/filestore_windows.go (about) 1 package 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 OS) 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) (OS, 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 OS(content), nil 35 }