filesystem.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 http://mozilla.org/MPL/2.0/.
  6. package fs
  7. import (
  8. "errors"
  9. "io"
  10. "time"
  11. )
  12. type LinkTargetType int
  13. const (
  14. LinkTargetFile LinkTargetType = iota
  15. LinkTargetDirectory
  16. LinkTargetUnknown
  17. )
  18. // The Filesystem interface abstracts access to the file system.
  19. type Filesystem interface {
  20. ChangeSymlinkType(name string, tt LinkTargetType) error
  21. Chmod(name string, mode FileMode) error
  22. Chtimes(name string, atime time.Time, mtime time.Time) error
  23. Create(name string) (File, error)
  24. CreateSymlink(name, target string, tt LinkTargetType) error
  25. DirNames(name string) ([]string, error)
  26. Lstat(name string) (FileInfo, error)
  27. Mkdir(name string, perm FileMode) error
  28. Open(name string) (File, error)
  29. ReadSymlink(name string) (string, LinkTargetType, error)
  30. Remove(name string) error
  31. Rename(oldname, newname string) error
  32. Stat(name string) (FileInfo, error)
  33. SymlinksSupported() bool
  34. Walk(root string, walkFn WalkFunc) error
  35. }
  36. // The File interface abstracts access to a regular file, being a somewhat
  37. // smaller interface than os.File
  38. type File interface {
  39. io.Reader
  40. io.WriterAt
  41. io.Closer
  42. Truncate(size int64) error
  43. }
  44. // The FileInfo interface is almost the same as os.FileInfo, but with the
  45. // Sys method removed (as we don't want to expose whatever is underlying)
  46. // and with a couple of convenience methods added.
  47. type FileInfo interface {
  48. // Standard things present in os.FileInfo
  49. Name() string
  50. Mode() FileMode
  51. Size() int64
  52. ModTime() time.Time
  53. IsDir() bool
  54. // Extensions
  55. IsRegular() bool
  56. IsSymlink() bool
  57. }
  58. // FileMode is similar to os.FileMode
  59. type FileMode uint32
  60. // DefaultFilesystem is the fallback to use when nothing explicitly has
  61. // been passed.
  62. var DefaultFilesystem Filesystem = new(BasicFilesystem)
  63. // SkipDir is used as a return value from WalkFuncs to indicate that
  64. // the directory named in the call is to be skipped. It is not returned
  65. // as an error by any function.
  66. var errSkipDir = errors.New("skip this directory")
  67. var SkipDir = errSkipDir // silences the lint warning...