filesystem.go 2.0 KB

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