Skip to content

Commit 9dc3fee

Browse files
author
JojiiOfficial
committed
improve file loading
1 parent d55dcc9 commit 9dc3fee

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

dmfs/fsFile.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,36 @@ type fileInode struct {
1616
file *libdm.FileResponseItem
1717
}
1818

19-
var _ = (fs.NodeGetattrer)((*fileInode)(nil))
19+
var (
20+
_ = (fs.NodeGetattrer)((*fileInode)(nil))
21+
_ = (fs.NodeUnlinker)((*fileInode)(nil))
22+
_ = (fs.NodeReader)((*fileInode)(nil))
23+
)
2024

2125
// Set file attributes
2226
func (fnode *fileInode) Getattr(ctx context.Context, f fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
2327
fmt.Println("getatr")
2428
out.Size = uint64(fnode.file.Size)
2529
out.Ctime = uint64(fnode.file.CreationDate.Unix())
2630
out.Mtime = out.Ctime
27-
out.Mode = 0640
31+
out.Mode = 0770
2832

2933
// Set owner/group
3034
data.setUserAttr(out)
3135

3236
return 0
3337
}
38+
39+
func (fnode *fileInode) getattr(out *fuse.AttrOut) {
40+
out.Size = uint64(fnode.file.Size)
41+
out.SetTimes(nil, &fnode.file.CreationDate, &fnode.file.CreationDate)
42+
}
43+
44+
func (fnode *fileInode) Unlink(ctx context.Context, name string) syscall.Errno {
45+
fmt.Println("rm", name)
46+
return 0
47+
}
48+
49+
func (fnode *fileInode) Read(ctx context.Context, f fs.FileHandle, dest []byte, off int64) (fuse.ReadResult, syscall.Errno) {
50+
return nil, syscall.ENOSPC
51+
}

dmfs/fsGroup.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const (
2020
var (
2121
_ = (fs.NodeReaddirer)((*groupNode)(nil))
2222
_ = (fs.NodeLookuper)((*groupNode)(nil))
23+
_ = (fs.NodeGetattrer)((*groupNode)(nil))
2324
)
2425

2526
type groupNode struct {
@@ -40,7 +41,6 @@ func newGroupNode(namespace, group string) *groupNode {
4041
isNoGroupPlaceholder: group == NoGroupFolder,
4142
}
4243
}
43-
4444
func (groupNode *groupNode) getRequestAttributes() libdatamanager.FileAttributes {
4545
// Don't send any group to get
4646
// all files without groups
@@ -57,7 +57,9 @@ func (groupNode *groupNode) getRequestAttributes() libdatamanager.FileAttributes
5757

5858
// List files in group
5959
func (groupNode *groupNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
60+
fmt.Println("readdir node")
6061
r := make([]fuse.DirEntry, 0)
62+
6163
files, err := data.loadFiles(groupNode.getRequestAttributes())
6264
if err != nil {
6365
return nil, syscall.EIO
@@ -68,15 +70,24 @@ func (groupNode *groupNode) Readdir(ctx context.Context) (fs.DirStream, syscall.
6870
Mode: syscall.S_IFREG,
6971
Name: files[i].Name,
7072
})
71-
72-
fmt.Println(files[i].Name)
7373
}
7474

7575
groupNode.files = files
76-
7776
return fs.NewListDirStream(r), 0
7877
}
7978

79+
func (groupNode *groupNode) loadfiles() error {
80+
fmt.Println("readdir node")
81+
82+
files, err := data.loadFiles(groupNode.getRequestAttributes())
83+
if err != nil {
84+
return err
85+
}
86+
87+
groupNode.files = files
88+
return nil
89+
}
90+
8091
func (groupNode *groupNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*fs.Inode, syscall.Errno) {
8192
file := groupNode.findFile(name)
8293
if file == nil {
@@ -106,3 +117,10 @@ func (groupNode *groupNode) findFile(name string) *libdatamanager.FileResponseIt
106117

107118
return nil
108119
}
120+
121+
// Set file attributes
122+
func (groupNode *groupNode) Getattr(ctx context.Context, f fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
123+
out.Mode = 0700
124+
data.setUserAttr(out)
125+
return 0
126+
}

0 commit comments

Comments
 (0)