filestore_windows.go 867 B

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