2024-05-05 20:23:07 +00:00
|
|
|
package fstree
|
2020-12-27 07:23:00 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"github.com/hanwen/go-fuse/v2/fs"
|
|
|
|
"github.com/hanwen/go-fuse/v2/fuse"
|
|
|
|
)
|
|
|
|
|
|
|
|
type groupNode struct {
|
|
|
|
fs.Inode
|
2020-12-29 03:51:23 +00:00
|
|
|
param *FSParam
|
2020-12-31 20:00:10 +00:00
|
|
|
|
2024-05-05 20:09:03 +00:00
|
|
|
source GroupSource
|
2020-12-31 20:00:10 +00:00
|
|
|
staticNodes map[string]staticNode
|
2020-12-27 07:23:00 +00:00
|
|
|
}
|
|
|
|
|
2024-05-05 20:09:03 +00:00
|
|
|
type GroupSource interface {
|
|
|
|
GetGroupID() uint64
|
2024-07-18 03:35:18 +00:00
|
|
|
InvalidateContentCache()
|
2024-05-05 20:09:03 +00:00
|
|
|
}
|
|
|
|
|
2020-12-27 07:23:00 +00:00
|
|
|
// Ensure we are implementing the NodeReaddirer interface
|
|
|
|
var _ = (fs.NodeReaddirer)((*groupNode)(nil))
|
|
|
|
|
|
|
|
// Ensure we are implementing the NodeLookuper interface
|
|
|
|
var _ = (fs.NodeLookuper)((*groupNode)(nil))
|
|
|
|
|
2024-05-05 20:09:03 +00:00
|
|
|
func newGroupNodeFromSource(source GroupSource, param *FSParam) (*groupNode, error) {
|
2020-12-27 07:23:00 +00:00
|
|
|
node := &groupNode{
|
2024-05-05 20:09:03 +00:00
|
|
|
param: param,
|
|
|
|
source: source,
|
2020-12-31 20:00:10 +00:00
|
|
|
staticNodes: map[string]staticNode{
|
2024-05-05 20:09:03 +00:00
|
|
|
".refresh": newRefreshNode(source, param),
|
2020-12-31 20:00:10 +00:00
|
|
|
},
|
2020-12-27 07:23:00 +00:00
|
|
|
}
|
|
|
|
return node, nil
|
|
|
|
}
|
|
|
|
|
2024-05-05 20:09:03 +00:00
|
|
|
func (n *groupNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
|
2024-08-05 01:45:51 +00:00
|
|
|
groups, repositories, err := n.param.GitForge.FetchGroupContent(n.source.GetGroupID())
|
2024-05-05 20:09:03 +00:00
|
|
|
if err != nil {
|
2024-06-06 05:51:34 +00:00
|
|
|
n.param.logger.Error(err.Error())
|
2020-12-27 07:23:00 +00:00
|
|
|
}
|
|
|
|
|
2024-05-05 20:09:03 +00:00
|
|
|
entries := make([]fuse.DirEntry, 0, len(groups)+len(repositories)+len(n.staticNodes))
|
|
|
|
for groupName, group := range groups {
|
2020-12-27 07:23:00 +00:00
|
|
|
entries = append(entries, fuse.DirEntry{
|
2024-05-05 20:09:03 +00:00
|
|
|
Name: groupName,
|
|
|
|
Ino: group.GetGroupID(),
|
2020-12-27 07:23:00 +00:00
|
|
|
Mode: fuse.S_IFDIR,
|
|
|
|
})
|
|
|
|
}
|
2024-05-05 20:09:03 +00:00
|
|
|
for repositoryName, repository := range repositories {
|
2020-12-27 07:23:00 +00:00
|
|
|
entries = append(entries, fuse.DirEntry{
|
2024-05-05 20:09:03 +00:00
|
|
|
Name: repositoryName,
|
|
|
|
Ino: repository.GetRepositoryID(),
|
2020-12-27 07:23:00 +00:00
|
|
|
Mode: fuse.S_IFLNK,
|
|
|
|
})
|
|
|
|
}
|
2020-12-31 20:00:10 +00:00
|
|
|
for name, staticNode := range n.staticNodes {
|
|
|
|
entries = append(entries, fuse.DirEntry{
|
|
|
|
Name: name,
|
|
|
|
Ino: staticNode.Ino(),
|
|
|
|
Mode: staticNode.Mode(),
|
|
|
|
})
|
|
|
|
}
|
2020-12-27 07:23:00 +00:00
|
|
|
return fs.NewListDirStream(entries), 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *groupNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*fs.Inode, syscall.Errno) {
|
2024-08-05 01:45:51 +00:00
|
|
|
groups, repositories, err := n.param.GitForge.FetchGroupContent(n.source.GetGroupID())
|
2024-08-04 22:59:57 +00:00
|
|
|
if err != nil {
|
|
|
|
n.param.logger.Error(err.Error())
|
|
|
|
} else {
|
|
|
|
// Check if the map of groups contains it
|
|
|
|
group, found := groups[name]
|
|
|
|
if found {
|
|
|
|
attrs := fs.StableAttr{
|
|
|
|
Ino: group.GetGroupID(),
|
|
|
|
Mode: fuse.S_IFDIR,
|
|
|
|
}
|
|
|
|
groupNode, _ := newGroupNodeFromSource(group, n.param)
|
|
|
|
return n.NewInode(ctx, groupNode, attrs), 0
|
2020-12-27 07:23:00 +00:00
|
|
|
}
|
|
|
|
|
2024-08-04 22:59:57 +00:00
|
|
|
// Check if the map of projects contains it
|
|
|
|
repository, found := repositories[name]
|
|
|
|
if found {
|
|
|
|
attrs := fs.StableAttr{
|
|
|
|
Ino: repository.GetRepositoryID(),
|
|
|
|
Mode: fuse.S_IFLNK,
|
|
|
|
}
|
|
|
|
repositoryNode, _ := newRepositoryNodeFromSource(repository, n.param)
|
|
|
|
return n.NewInode(ctx, repositoryNode, attrs), 0
|
2020-12-27 07:23:00 +00:00
|
|
|
}
|
2020-12-31 20:00:10 +00:00
|
|
|
|
2024-08-04 22:59:57 +00:00
|
|
|
// Check if the map of static nodes contains it
|
|
|
|
staticNode, ok := n.staticNodes[name]
|
|
|
|
if ok {
|
|
|
|
attrs := fs.StableAttr{
|
|
|
|
Ino: staticNode.Ino(),
|
|
|
|
Mode: staticNode.Mode(),
|
|
|
|
}
|
|
|
|
return n.NewInode(ctx, staticNode, attrs), 0
|
2020-12-31 20:00:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-27 07:23:00 +00:00
|
|
|
return nil, syscall.ENOENT
|
|
|
|
}
|