2018-02-05 16:05:59 -05:00
|
|
|
package layer // import "github.com/docker/docker/layer"
|
2017-04-25 12:37:29 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2017-11-20 11:33:20 -05:00
|
|
|
// setOS writes the "os" file to the layer filestore
|
|
|
|
func (fm *fileMetadataTransaction) setOS(os string) error {
|
2017-08-08 15:43:48 -04:00
|
|
|
if os == "" {
|
2017-04-25 12:37:29 -04:00
|
|
|
return nil
|
|
|
|
}
|
2017-08-08 15:43:48 -04:00
|
|
|
return fm.ws.WriteFile("os", []byte(os), 0644)
|
2017-04-25 12:37:29 -04:00
|
|
|
}
|
|
|
|
|
2017-11-20 11:33:20 -05:00
|
|
|
// getOS reads the "os" file from the layer filestore
|
|
|
|
func (fms *fileMetadataStore) getOS(layer ChainID) (string, error) {
|
2021-08-24 06:10:50 -04:00
|
|
|
contentBytes, err := os.ReadFile(fms.getLayerFilename(layer, "os"))
|
2017-04-25 12:37:29 -04:00
|
|
|
if err != nil {
|
2017-08-08 15:43:48 -04:00
|
|
|
// For backwards compatibility, the os file may not exist. Default to "windows" if missing.
|
2017-04-25 12:37:29 -04:00
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return "windows", nil
|
|
|
|
}
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
content := strings.TrimSpace(string(contentBytes))
|
|
|
|
|
|
|
|
if content != "windows" && content != "linux" {
|
2017-08-08 15:43:48 -04:00
|
|
|
return "", fmt.Errorf("invalid operating system value: %s", content)
|
2017-04-25 12:37:29 -04:00
|
|
|
}
|
|
|
|
|
2017-08-24 14:48:16 -04:00
|
|
|
return content, nil
|
2017-04-25 12:37:29 -04:00
|
|
|
}
|