File tree Expand file tree Collapse file tree 5 files changed +84
-5
lines changed
Expand file tree Collapse file tree 5 files changed +84
-5
lines changed Original file line number Diff line number Diff line change @@ -18,15 +18,15 @@ type dmanagerFilesystem struct {
1818 libdm * libdatamanager.LibDM
1919}
2020
21- // Ensure that we implement NodeOnAdder
21+ // implement the interfaces
2222var _ = (fs .NodeOnAdder )((* dmanagerFilesystem )(nil ))
2323var _ = (fs .NodeRenamer )((* dmanagerFilesystem )(nil ))
2424var _ = (fs .NodeUnlinker )((* dmanagerFilesystem )(nil ))
2525
2626// OnAdd is called on mounting the file system. Use it to populate
2727// the file system tree.
2828func (root * dmanagerFilesystem ) OnAdd (ctx context.Context ) {
29- root .initFiles ()
29+ root .initFiles (ctx )
3030}
3131
3232// Unlink if virtual file was unlinked
Original file line number Diff line number Diff line change 11package dmfs
22
3- func (root * dmanagerFilesystem ) initFiles () {
3+ import (
4+ "context"
5+ "log"
6+ "syscall"
7+
8+ "github.com/hanwen/go-fuse/v2/fs"
9+ )
10+
11+ func (root * dmanagerFilesystem ) initFiles (ctx context.Context ) {
412 root .debug ("Init files" )
13+
14+ userData , err := root .libdm .GetUserAttributeData ()
15+ if err != nil {
16+ log .Fatal (err )
17+ return
18+ }
19+
20+ // Loop Namespaces and add childs in as folders
21+ for _ , namespace := range userData .Namespace {
22+ nsName := removeNSName (namespace .Name )
23+
24+ // reuse child
25+ nsp := root .Inode .GetChild (nsName )
26+
27+ // Create namespace folder
28+ if nsp == nil {
29+ nsp = root .Inode .NewInode (ctx , & fs.Inode {}, fs.StableAttr {
30+ Mode : syscall .S_IFDIR ,
31+ })
32+ root .AddChild (nsName , nsp , true )
33+ }
34+
35+ // Use a no_group folder for files
36+ // not associated to a groud
37+ if len (namespace .Groups ) == 0 {
38+ namespace .Groups = []string {"no_group" }
39+ }
40+
41+ // Add groups to namespace
42+ for _ , group := range namespace .Groups {
43+ gp := nsp .GetChild (group )
44+ if gp == nil {
45+ gp = nsp .NewInode (ctx , & fs.Inode {}, fs.StableAttr {
46+ Mode : syscall .S_IFDIR ,
47+ })
48+ nsp .AddChild (group , gp , true )
49+ }
50+ }
51+ }
52+
53+ root .debug ("Init files success" )
554}
Original file line number Diff line number Diff line change @@ -87,8 +87,13 @@ func (mounter *Mounter) Mount() {
8787
8888// Umount fs
8989func (mounter * Mounter ) umount () {
90- mounter .server .Unmount ()
91- fmt .Println ("Umounted" )
90+ err := mounter .server .Unmount ()
91+ if err != nil {
92+ fmt .Println (err )
93+ } else {
94+ fmt .Println ("Umounted" )
95+ }
96+
9297 mounter .doneChan <- true
9398}
9499
Original file line number Diff line number Diff line change 1+ package dmfs
2+
3+ import (
4+ "strings"
5+
6+ libdm "github.com/DataManager-Go/libdatamanager"
7+ )
8+
9+ func removeNSName (ns string ) string {
10+ if ! strings .Contains (ns , "_" ) {
11+ return ns
12+ }
13+
14+ return ns [strings .Index (ns , "_" )+ 1 :]
15+ }
16+
17+ func addNSName (ns string , libdm * libdm.RequestConfig ) string {
18+ userPrefix := libdm .Username + "_"
19+ if strings .HasPrefix (ns , userPrefix ) {
20+ return ns
21+ }
22+
23+ return userPrefix + ns
24+ }
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD
4242github.com/jinzhu/inflection v1.0.0 /go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc =
4343github.com/jinzhu/now v1.0.1 h1:HjfetcXq097iXP0uoPCdnM4Efp5/9MsM0/M+XOTeR3M =
4444github.com/jinzhu/now v1.0.1 /go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8 =
45+ github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4 =
4546github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 /go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k =
4647github.com/lib/pq v1.1.1 h1:sJZmqHoEaY7f+NPP8pgLB/WxulyR3fewgCM2qaSlBb4 =
4748github.com/lib/pq v1.1.1 /go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo =
You can’t perform that action at this time.
0 commit comments