github.com/kaisenlinux/docker@v0.0.0-20230510090727-ea55db55fac7/engine/layer/filestore_windows.go (about)

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