filesystemtype.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 int32
  9. const (
  10. FilesystemTypeBasic FilesystemType = 0
  11. FilesystemTypeFake FilesystemType = 1
  12. )
  13. func (t FilesystemType) String() string {
  14. switch t {
  15. case FilesystemTypeBasic:
  16. return "basic"
  17. case FilesystemTypeFake:
  18. return "fake"
  19. default:
  20. return "unknown"
  21. }
  22. }
  23. func (t FilesystemType) ToFS() fs.FilesystemType {
  24. switch t {
  25. case FilesystemTypeBasic:
  26. return fs.FilesystemTypeBasic
  27. case FilesystemTypeFake:
  28. return fs.FilesystemTypeFake
  29. default:
  30. return fs.FilesystemTypeBasic
  31. }
  32. }
  33. func (t FilesystemType) MarshalText() ([]byte, error) {
  34. return []byte(t.String()), nil
  35. }
  36. func (t *FilesystemType) UnmarshalText(bs []byte) error {
  37. switch string(bs) {
  38. case "basic":
  39. *t = FilesystemTypeBasic
  40. case "fake":
  41. *t = FilesystemTypeFake
  42. default:
  43. *t = FilesystemTypeBasic
  44. }
  45. return nil
  46. }