@@ -2,10 +2,13 @@ package dmfs
22
33import (
44 "context"
5+ "fmt"
56 "syscall"
67
78 "github.com/DataManager-Go/libdatamanager"
9+ libdm "github.com/DataManager-Go/libdatamanager"
810 "github.com/hanwen/go-fuse/v2/fs"
11+ "github.com/hanwen/go-fuse/v2/fuse"
912)
1013
1114const (
@@ -15,44 +18,91 @@ const (
1518)
1619
1720var (
18- _ = (fs .NodeOnAdder )((* groupInode )(nil ))
21+ _ = (fs .NodeReaddirer )((* groupNode )(nil ))
22+ _ = (fs .NodeLookuper )((* groupNode )(nil ))
1923)
2024
21- type groupInode struct {
25+ type groupNode struct {
2226 fs.Inode
2327
2428 namespace string
2529 group string
2630 isNoGroupPlaceholder bool
31+
32+ files []libdm.FileResponseItem
2733}
2834
29- // List files
30- func (groupInode * groupInode ) OnAdd (ctx context.Context ) {
31- groupAdd := []string {groupInode .group }
35+ // Create a new group node
36+ func newGroupNode (namespace , group string ) * groupNode {
37+ return & groupNode {
38+ namespace : namespace ,
39+ group : group ,
40+ isNoGroupPlaceholder : group == NoGroupFolder ,
41+ }
42+ }
3243
33- // Check if group is no_group
34- if len (groupAdd ) == 1 && groupAdd [0 ] == NoGroupFolder {
35- groupInode .isNoGroupPlaceholder = true
36- groupAdd = []string {}
44+ func (groupNode * groupNode ) getRequestAttributes () libdatamanager.FileAttributes {
45+ // Don't send any group to get
46+ // all files without groups
47+ reqGroup := []string {groupNode .group }
48+ if groupNode .isNoGroupPlaceholder {
49+ reqGroup = []string {}
3750 }
3851
39- files , err := data .libdm .ListFiles ("" , 0 , false , libdatamanager.FileAttributes {
40- Groups : groupAdd ,
41- Namespace : groupInode .namespace ,
42- }, 0 )
52+ return libdatamanager.FileAttributes {
53+ Namespace : groupNode .namespace ,
54+ Groups : reqGroup ,
55+ }
56+ }
4357
58+ // List files in group
59+ func (groupNode * groupNode ) Readdir (ctx context.Context ) (fs.DirStream , syscall.Errno ) {
60+ r := make ([]fuse.DirEntry , 0 )
61+ files , err := data .loadFiles (groupNode .getRequestAttributes ())
4462 if err != nil {
45- printResponseError (err , "getting files for " + groupInode .group )
46- return
63+ return nil , syscall .EIO
64+ }
65+
66+ for i := range files {
67+ r = append (r , fuse.DirEntry {
68+ Mode : syscall .S_IFREG ,
69+ Name : files [i ].Name ,
70+ })
71+
72+ fmt .Println (files [i ].Name )
4773 }
4874
49- for _ , file := range files .Files {
50- fileNode := groupInode .NewInode (ctx , & fileInode {
51- file : & file ,
75+ groupNode .files = files
76+
77+ return fs .NewListDirStream (r ), 0
78+ }
79+
80+ func (groupNode * groupNode ) Lookup (ctx context.Context , name string , out * fuse.EntryOut ) (* fs.Inode , syscall.Errno ) {
81+ file := groupNode .findFile (name )
82+ if file == nil {
83+ return nil , syscall .ENOENT
84+ }
85+
86+ file .Attributes .Namespace = groupNode .namespace
87+
88+ child := groupNode .GetChild (name )
89+ if child == nil {
90+ child = groupNode .NewInode (ctx , & fileInode {
91+ file : file ,
5292 }, fs.StableAttr {
5393 Mode : syscall .S_IFREG ,
5494 })
95+ }
5596
56- groupInode .AddChild (file .Name , fileNode , true )
97+ return child , 0
98+ }
99+
100+ func (groupNode * groupNode ) findFile (name string ) * libdatamanager.FileResponseItem {
101+ for i := range groupNode .files {
102+ if groupNode .files [i ].Name == name {
103+ return & groupNode .files [i ]
104+ }
57105 }
106+
107+ return nil
58108}
0 commit comments