You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

dir_handle.go 3.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package mount
  2. import (
  3. "io"
  4. "os"
  5. "time"
  6. )
  7. // 目录从设计上来说不需要打开操作,所以dirHandle就是fusefs的DirHandle接口的完整实现。
  8. type dirHandle struct {
  9. dir FsDir
  10. dirReader DirReader
  11. }
  12. func newDirHandle(dir FsDir, dirReader DirReader) *dirHandle {
  13. return &dirHandle{dir: dir, dirReader: dirReader}
  14. }
  15. // Readdir reads the contents of the directory associated with file and returns
  16. // a slice of up to n FileInfo values, as would be returned by Lstat, in
  17. // directory order. Subsequent calls on the same file will yield further
  18. // FileInfos.
  19. //
  20. // If n > 0, Readdir returns at most n FileInfo structures. In this case, if
  21. // Readdir returns an empty slice, it will return a non-nil error explaining
  22. // why. At the end of a directory, the error is io.EOF.
  23. //
  24. // If n <= 0, Readdir returns all the FileInfo from the directory in a single
  25. // slice. In this case, if Readdir succeeds (reads all the way to the end of
  26. // the directory), it returns the slice and a nil error. If it encounters an
  27. // error before the end of the directory, Readdir returns the FileInfo read
  28. // until that point and a non-nil error.
  29. func (fh *dirHandle) Readdir(n int) (fis []os.FileInfo, err error) {
  30. entries, err := fh.dirReader.Next(n)
  31. if err != nil {
  32. return nil, err
  33. }
  34. if len(entries) == 0 {
  35. return nil, io.EOF
  36. }
  37. var infos []os.FileInfo
  38. for _, entry := range entries {
  39. infos = append(infos, &fileInfo{entry})
  40. }
  41. return infos, nil
  42. }
  43. // Readdirnames reads and returns a slice of names from the directory f.
  44. //
  45. // If n > 0, Readdirnames returns at most n names. In this case, if
  46. // Readdirnames returns an empty slice, it will return a non-nil error
  47. // explaining why. At the end of a directory, the error is io.EOF.
  48. //
  49. // If n <= 0, Readdirnames returns all the names from the directory in a single
  50. // slice. In this case, if Readdirnames succeeds (reads all the way to the end
  51. // of the directory), it returns the slice and a nil error. If it encounters an
  52. // error before the end of the directory, Readdirnames returns the names read
  53. // until that point and a non-nil error.
  54. func (fh *dirHandle) Readdirnames(n int) (names []string, err error) {
  55. entries, err := fh.dirReader.Next(n)
  56. if err != nil {
  57. return nil, err
  58. }
  59. if len(entries) == 0 {
  60. return nil, io.EOF
  61. }
  62. for _, entry := range entries {
  63. names = append(names, entry.Name())
  64. }
  65. return names, nil
  66. }
  67. // Close closes the handle
  68. func (fh *dirHandle) Close() (err error) {
  69. fh.dirReader.Close()
  70. return nil
  71. }
  72. type fileInfo struct {
  73. entry FsEntry
  74. }
  75. func (fi *fileInfo) Name() string {
  76. return fi.entry.Name()
  77. }
  78. func (fi *fileInfo) Size() int64 {
  79. return fi.entry.Size()
  80. }
  81. func (fi *fileInfo) Mode() os.FileMode {
  82. return os.FileMode(fi.entry.Mode())
  83. }
  84. // ModTime returns the modification time of the file
  85. func (fi *fileInfo) ModTime() time.Time {
  86. return fi.entry.ModTime()
  87. }
  88. func (fi *fileInfo) IsDir() bool {
  89. return fi.entry.IsDir()
  90. }
  91. func (fi *fileInfo) Sys() interface{} {
  92. return nil
  93. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。