Skip to content

Commit bc00a28

Browse files
author
JojiiOfficial
committed
implement listing files
improve groups add retrieve fileIDs
1 parent a4423ab commit bc00a28

File tree

5 files changed

+132
-17
lines changed

5 files changed

+132
-17
lines changed

dmfs/data.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package dmfs
2+
3+
import (
4+
"os"
5+
6+
"github.com/DataManager-Go/libdatamanager"
7+
libdm "github.com/DataManager-Go/libdatamanager"
8+
dmConfig "github.com/DataManager-Go/libdatamanager/config"
9+
)
10+
11+
var data dataStruct
12+
13+
// data provides the data for the fs
14+
type dataStruct struct {
15+
mounter *Mounter
16+
config *dmConfig.Config
17+
libdm *libdatamanager.LibDM
18+
19+
userAttributes *libdm.UserAttributeDataResponse
20+
gid, uid uint32
21+
}
22+
23+
func initData() {
24+
data.gid = uint32(os.Getegid())
25+
data.uid = uint32(os.Getuid())
26+
}
27+
28+
// load user attributes (namespaces, groups)
29+
func (data *dataStruct) loadUserAttributes() error {
30+
var err error
31+
data.userAttributes, err = data.libdm.GetUserAttributeData()
32+
if err != nil {
33+
return err
34+
}
35+
36+
return nil
37+
}

dmfs/dmfsRoot.go

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,11 @@ import (
77
"syscall"
88
"time"
99

10-
"github.com/DataManager-Go/libdatamanager"
11-
dmConfig "github.com/DataManager-Go/libdatamanager/config"
1210
"github.com/hanwen/go-fuse/v2/fs"
1311
)
1412

1513
type dmanagerRoot struct {
1614
fs.Inode
17-
18-
mounter *Mounter
19-
config *dmConfig.Config
20-
libdm *libdatamanager.LibDM
2115
}
2216

2317
// implement the interfaces
@@ -30,14 +24,14 @@ var _ = (fs.NodeRmdirer)((*dmanagerRoot)(nil))
3024
func (root *dmanagerRoot) OnAdd(ctx context.Context) {
3125
root.debug("Init files")
3226

33-
userData, err := root.libdm.GetUserAttributeData()
27+
err := data.loadUserAttributes()
3428
if err != nil {
3529
log.Fatal(err)
3630
return
3731
}
3832

3933
// Loop Namespaces and add childs in as folders
40-
for _, namespace := range userData.Namespace {
34+
for _, namespace := range data.userAttributes.Namespace {
4135
nsName := removeNSName(namespace.Name)
4236

4337
// reuse child
@@ -61,7 +55,10 @@ func (root *dmanagerRoot) OnAdd(ctx context.Context) {
6155
for _, group := range namespace.Groups {
6256
gp := nsp.GetChild(group)
6357
if gp == nil {
64-
gp = nsp.NewInode(ctx, &fs.Inode{}, fs.StableAttr{
58+
gp = nsp.NewInode(ctx, &groupInode{
59+
group: group,
60+
namespace: namespace.Name,
61+
}, fs.StableAttr{
6562
Mode: syscall.S_IFDIR,
6663
})
6764

@@ -76,7 +73,7 @@ func (root *dmanagerRoot) OnAdd(ctx context.Context) {
7673

7774
// Unlink if virtual file was unlinked
7875
func (root *dmanagerRoot) Rmdir(ctx context.Context, name string) syscall.Errno {
79-
namespace := addNSName(name, root.libdm.Config)
76+
namespace := addNSName(name, data.libdm.Config)
8077

8178
// wait 2 seconds to ensure, user didn't cancel
8279
select {
@@ -86,7 +83,7 @@ func (root *dmanagerRoot) Rmdir(ctx context.Context, name string) syscall.Errno
8683
}
8784

8885
// Do delete request
89-
if _, err := root.libdm.DeleteNamespace(namespace); err != nil {
86+
if _, err := data.libdm.DeleteNamespace(namespace); err != nil {
9087
fmt.Println(err)
9188
return syscall.EFAULT
9289
}
@@ -103,12 +100,12 @@ func (root *dmanagerRoot) Rename(ctx context.Context, name string, newParent fs.
103100
}
104101

105102
// Get real namespace names
106-
oldNSName := addNSName(name, root.libdm.Config)
107-
newNSName := addNSName(newName, root.libdm.Config)
103+
oldNSName := addNSName(name, data.libdm.Config)
104+
newNSName := addNSName(newName, data.libdm.Config)
108105
root.debug("rename namespace", oldNSName, "->", newNSName)
109106

110107
// Make rename request
111-
_, err := root.libdm.UpdateNamespace(oldNSName, newNSName)
108+
_, err := data.libdm.UpdateNamespace(oldNSName, newNSName)
112109
if err != nil {
113110
fmt.Println(err)
114111
return syscall.ENONET
@@ -119,7 +116,7 @@ func (root *dmanagerRoot) Rename(ctx context.Context, name string, newParent fs.
119116
}
120117

121118
func (root *dmanagerRoot) debug(arg ...interface{}) {
122-
if root.mounter.Debug {
119+
if data.mounter.Debug {
123120
fmt.Println(arg...)
124121
}
125122
}

dmfs/fsFile.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package dmfs
2+
3+
import (
4+
"context"
5+
"syscall"
6+
7+
libdm "github.com/DataManager-Go/libdatamanager"
8+
"github.com/hanwen/go-fuse/v2/fs"
9+
"github.com/hanwen/go-fuse/v2/fuse"
10+
)
11+
12+
type fileInode struct {
13+
fs.Inode
14+
15+
file *libdm.FileResponseItem
16+
}
17+
18+
var _ = (fs.NodeGetattrer)((*fileInode)(nil))
19+
20+
// Set attributes for files
21+
func (fnode *fileInode) Getattr(ctx context.Context, f fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
22+
out.Size = uint64(fnode.file.Size)
23+
out.Ctime = uint64(fnode.file.CreationDate.Unix())
24+
out.Mtime = out.Ctime
25+
out.Mode = 0640
26+
out.Gid = data.gid
27+
out.Uid = data.uid
28+
29+
return 0
30+
}

dmfs/fsGroup.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package dmfs
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"syscall"
7+
8+
"github.com/DataManager-Go/libdatamanager"
9+
"github.com/hanwen/go-fuse/v2/fs"
10+
)
11+
12+
type groupInode struct {
13+
fs.Inode
14+
15+
namespace string
16+
group string
17+
}
18+
19+
var _ = (fs.NodeOnAdder)((*groupInode)(nil))
20+
21+
func (groupInode *groupInode) OnAdd(ctx context.Context) {
22+
groupAdd := []string{groupInode.group}
23+
24+
if len(groupAdd) == 1 && groupAdd[0] == "no_group" {
25+
groupAdd = []string{}
26+
}
27+
28+
files, err := data.libdm.ListFiles("", 0, false, libdatamanager.FileAttributes{
29+
Groups: groupAdd,
30+
Namespace: groupInode.namespace,
31+
}, 0)
32+
33+
if err != nil {
34+
fmt.Println(err)
35+
return
36+
}
37+
38+
for _, file := range files.Files {
39+
fileNode := groupInode.NewInode(ctx, &fileInode{
40+
file: &file,
41+
}, fs.StableAttr{
42+
Mode: syscall.S_IFREG,
43+
})
44+
45+
groupInode.AddChild(file.Name, fileNode, true)
46+
}
47+
}

dmfs/mount.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,17 @@ func (mounter *Mounter) Mount() {
4545
exitChan := make(chan bool, 1)
4646
mounter.doneChan = make(chan bool, 1)
4747

48-
// Create the fs
49-
root := &dmanagerRoot{
48+
data = dataStruct{
5049
mounter: mounter,
5150
config: mounter.Config,
5251
libdm: mounter.Libdm,
5352
}
5453

54+
initData()
55+
56+
// Create the fs
57+
root := &dmanagerRoot{}
58+
5559
var err error
5660

5761
// Mount fs

0 commit comments

Comments
 (0)