filesystemtype.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright (C) 2016 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package config
  7. import "github.com/syncthing/syncthing/lib/fs"
  8. type FilesystemType string
  9. const (
  10. FilesystemTypeBasic FilesystemType = "basic"
  11. FilesystemTypeFake FilesystemType = "fake"
  12. )
  13. func (t FilesystemType) ToFS() fs.FilesystemType {
  14. if t == "" {
  15. // legacy compat, zero value means basic
  16. return fs.FilesystemTypeBasic
  17. }
  18. return fs.FilesystemType(string(t))
  19. }
  20. func (t FilesystemType) String() string {
  21. if t == "" {
  22. // legacy compat, zero value means basic
  23. return string(FilesystemTypeBasic)
  24. }
  25. return string(t)
  26. }
  27. func (t FilesystemType) MarshalText() ([]byte, error) {
  28. return []byte(t.String()), nil
  29. }
  30. func (t *FilesystemType) UnmarshalText(bs []byte) error {
  31. if len(bs) == 0 {
  32. // legacy compat, zero value means basic
  33. *t = FilesystemTypeBasic
  34. return nil
  35. }
  36. *t = FilesystemType(string(bs))
  37. return nil
  38. }
  39. func (t *FilesystemType) ParseDefault(str string) error {
  40. return t.UnmarshalText([]byte(str))
  41. }