filestore_windows.go 837 B

1234567891011121314151617181920212223242526272829303132333435
  1. package layer
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "os"
  6. "strings"
  7. )
  8. // SetOS writes the "os" file to the layer filestore
  9. func (fm *fileMetadataTransaction) SetOS(os OS) error {
  10. if os == "" {
  11. return nil
  12. }
  13. return fm.ws.WriteFile("os", []byte(os), 0644)
  14. }
  15. // GetOS reads the "os" file from the layer filestore
  16. func (fms *fileMetadataStore) GetOS(layer ChainID) (OS, error) {
  17. contentBytes, err := ioutil.ReadFile(fms.getLayerFilename(layer, "os"))
  18. if err != nil {
  19. // For backwards compatibility, the os 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 operating system value: %s", content)
  28. }
  29. return OS(content), nil
  30. }