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.

fuse_package.go 2.6 kB

8 months ago
8 months ago
8 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package vfs
  2. import (
  3. "context"
  4. "os"
  5. "time"
  6. "gitlink.org.cn/cloudream/storage2/client/internal/mount/fuse"
  7. "gitlink.org.cn/cloudream/storage2/client/internal/mount/vfs/cache"
  8. )
  9. type FusePackage struct {
  10. vfs *Vfs
  11. bktName string
  12. pkgName string
  13. modTime time.Time
  14. mode os.FileMode
  15. }
  16. func newPackageFromCache(cache cache.CacheEntryInfo, vfs *Vfs) fuse.FsDir {
  17. pathComps := cache.PathComps
  18. return &FusePackage{
  19. vfs: vfs,
  20. bktName: pathComps[0],
  21. pkgName: pathComps[1],
  22. modTime: cache.ModTime,
  23. mode: cache.Mode,
  24. }
  25. }
  26. func (r *FusePackage) PathComps() []string {
  27. return []string{r.bktName, r.pkgName}
  28. }
  29. func (r *FusePackage) Name() string {
  30. return r.pkgName
  31. }
  32. func (r *FusePackage) Size() int64 {
  33. return 0
  34. }
  35. func (r *FusePackage) Mode() os.FileMode {
  36. return os.ModeDir | r.mode
  37. }
  38. func (r *FusePackage) ModTime() time.Time {
  39. return r.modTime
  40. }
  41. func (r *FusePackage) IsDir() bool {
  42. return true
  43. }
  44. func (r *FusePackage) SetModTime(time time.Time) error {
  45. dir := r.loadCacheDir()
  46. if dir == nil {
  47. return fuse.ErrNotExists
  48. }
  49. return dir.SetModTime(time)
  50. }
  51. // 如果不存在,应该返回ErrNotExists
  52. func (r *FusePackage) Child(ctx context.Context, name string) (fuse.FsEntry, error) {
  53. return child(r.vfs, ctx, r, name)
  54. }
  55. func (r *FusePackage) Children(ctx context.Context) ([]fuse.FsEntry, error) {
  56. return listChildren(r.vfs, ctx, r)
  57. }
  58. func (r *FusePackage) ReadChildren() (fuse.DirReader, error) {
  59. ens, err := listChildren(r.vfs, context.Background(), r)
  60. if err != nil {
  61. return nil, err
  62. }
  63. return newFuseDirReader(ens), nil
  64. }
  65. func (r *FusePackage) NewDir(ctx context.Context, name string) (fuse.FsDir, error) {
  66. return newDir(r.vfs, ctx, name, r)
  67. }
  68. func (r *FusePackage) NewFile(ctx context.Context, name string, flags uint32) (fuse.FileHandle, uint32, error) {
  69. return newFile(r.vfs, ctx, name, r, flags)
  70. }
  71. func (r *FusePackage) RemoveChild(ctx context.Context, name string) error {
  72. return removeChild(r.vfs, ctx, name, r)
  73. }
  74. func (r *FusePackage) MoveChild(ctx context.Context, oldName string, newName string, newParent fuse.FsDir) error {
  75. return moveChild(r.vfs, ctx, oldName, r, newName, newParent.(FuseNode))
  76. }
  77. func (r *FusePackage) loadCacheDir() *cache.CacheDir {
  78. var createOpt *cache.CreateDirOption
  79. pkg, err := r.vfs.db.Package().GetByFullName(r.vfs.db.DefCtx(), r.bktName, r.pkgName)
  80. if err == nil {
  81. createOpt = &cache.CreateDirOption{
  82. ModTime: pkg.CreateTime,
  83. }
  84. }
  85. return r.vfs.cache.LoadDir([]string{r.bktName, r.pkgName}, createOpt)
  86. }
  87. var _ fuse.FsDir = (*FusePackage)(nil)
  88. var _ FuseNode = (*FusePackage)(nil)

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