filestore_windows.go 919 B

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