Skip to content

Commit 8dd1434

Browse files
author
JojiiOfficial
committed
improve codestyle
1 parent 33ac9bf commit 8dd1434

File tree

4 files changed

+95
-103
lines changed

4 files changed

+95
-103
lines changed

dmfs/dmfs.go

Lines changed: 0 additions & 48 deletions
This file was deleted.

dmfs/dmfsRoot.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package dmfs
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"log"
7+
"syscall"
8+
9+
"github.com/DataManager-Go/libdatamanager"
10+
dmConfig "github.com/DataManager-Go/libdatamanager/config"
11+
"github.com/hanwen/go-fuse/v2/fs"
12+
)
13+
14+
type dmanagerRoot struct {
15+
fs.Inode
16+
17+
mounter *Mounter
18+
config *dmConfig.Config
19+
libdm *libdatamanager.LibDM
20+
}
21+
22+
// implement the interfaces
23+
var _ = (fs.NodeOnAdder)((*dmanagerRoot)(nil))
24+
var _ = (fs.NodeRenamer)((*dmanagerRoot)(nil))
25+
var _ = (fs.NodeRmdirer)((*dmanagerRoot)(nil))
26+
27+
// OnAdd is called on mounting the file system. Use it to populate
28+
// the file system tree.
29+
func (root *dmanagerRoot) OnAdd(ctx context.Context) {
30+
root.debug("Init files")
31+
32+
userData, err := root.libdm.GetUserAttributeData()
33+
if err != nil {
34+
log.Fatal(err)
35+
return
36+
}
37+
38+
// Loop Namespaces and add childs in as folders
39+
for _, namespace := range userData.Namespace {
40+
nsName := removeNSName(namespace.Name)
41+
42+
// reuse child
43+
nsp := root.Inode.GetChild(nsName)
44+
45+
// Create namespace folder
46+
if nsp == nil {
47+
nsp = root.Inode.NewInode(ctx, &fs.Inode{}, fs.StableAttr{
48+
Mode: syscall.S_IFDIR,
49+
})
50+
root.AddChild(nsName, nsp, true)
51+
}
52+
53+
// Use a no_group folder for files
54+
// not associated to a groud
55+
if len(namespace.Groups) == 0 {
56+
namespace.Groups = []string{"no_group"}
57+
}
58+
59+
// Add groups to namespace
60+
for _, group := range namespace.Groups {
61+
gp := nsp.GetChild(group)
62+
if gp == nil {
63+
gp = nsp.NewInode(ctx, &fs.Inode{}, fs.StableAttr{
64+
Mode: syscall.S_IFDIR,
65+
})
66+
67+
nsp.AddChild(group, gp, true)
68+
}
69+
}
70+
}
71+
72+
root.debug("Init files success")
73+
74+
}
75+
76+
// Unlink if virtual file was unlinked
77+
func (root *dmanagerRoot) Rmdir(ctx context.Context, name string) syscall.Errno {
78+
namespace := addNSName(name, root.libdm.Config)
79+
// TODO delete namespace
80+
fmt.Println("rm", namespace)
81+
return 0
82+
}
83+
84+
// Rename if virtual file was renamed
85+
func (root *dmanagerRoot) Rename(ctx context.Context, name string, newParent fs.InodeEmbedder, newName string, flags uint32) syscall.Errno {
86+
fmt.Println("renome")
87+
return 0
88+
}
89+
90+
func (root *dmanagerRoot) debug(arg ...interface{}) {
91+
if root.mounter.Debug {
92+
fmt.Println(arg...)
93+
}
94+
}

dmfs/initFiles.go

Lines changed: 0 additions & 54 deletions
This file was deleted.

dmfs/mount.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (mounter *Mounter) Mount() {
4545
mounter.doneChan = make(chan bool, 1)
4646

4747
// Create the fs
48-
root := &dmanagerFilesystem{
48+
root := &dmanagerRoot{
4949
mounter: mounter,
5050
config: mounter.Config,
5151
libdm: mounter.Libdm,

0 commit comments

Comments
 (0)