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

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

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