rename fs package to fstree to avoid collision with go-fuse

This commit is contained in:
Massaki Archambault 2024-05-05 16:23:07 -04:00
parent 5ed64d523e
commit 0c647a692f
8 changed files with 28 additions and 28 deletions

View File

@ -1,4 +1,4 @@
package fs package fstree
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package fs package fstree
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package fs package fstree
import ( import (
"context" "context"
@ -7,7 +7,7 @@ import (
"github.com/hanwen/go-fuse/v2/fs" "github.com/hanwen/go-fuse/v2/fs"
) )
type RepositoryNode struct { type repositoryNode struct {
fs.Inode fs.Inode
param *FSParam param *FSParam
@ -22,10 +22,10 @@ type RepositorySource interface {
} }
// Ensure we are implementing the NodeReaddirer interface // Ensure we are implementing the NodeReaddirer interface
var _ = (fs.NodeReadlinker)((*RepositoryNode)(nil)) var _ = (fs.NodeReadlinker)((*repositoryNode)(nil))
func newRepositoryNodeFromSource(source RepositorySource, param *FSParam) (*RepositoryNode, error) { func newRepositoryNodeFromSource(source RepositorySource, param *FSParam) (*repositoryNode, error) {
node := &RepositoryNode{ node := &repositoryNode{
param: param, param: param,
source: source, source: source,
} }
@ -34,7 +34,7 @@ func newRepositoryNodeFromSource(source RepositorySource, param *FSParam) (*Repo
return node, nil return node, nil
} }
func (n *RepositoryNode) Readlink(ctx context.Context) ([]byte, syscall.Errno) { func (n *repositoryNode) Readlink(ctx context.Context) ([]byte, syscall.Errno) {
// Create the local copy of the repo // Create the local copy of the repo
// TODO: cleanup // TODO: cleanup
localRepositoryPath, _ := n.param.GitImplementation.CloneOrPull(n.source.GetCloneURL(), int(n.source.GetRepositoryID()), n.source.GetDefaultBranch()) localRepositoryPath, _ := n.param.GitImplementation.CloneOrPull(n.source.GetCloneURL(), int(n.source.GetRepositoryID()), n.source.GetDefaultBranch())

View File

@ -1,4 +1,4 @@
package fs package fstree
import ( import (
"context" "context"

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"slices" "slices"
"github.com/badjware/gitlabfs/fs" "github.com/badjware/gitlabfs/fstree"
"github.com/xanzy/go-gitlab" "github.com/xanzy/go-gitlab"
) )
@ -27,7 +27,7 @@ type gitlabClient struct {
client *gitlab.Client client *gitlab.Client
// root group cache // root group cache
rootGroupCache map[string]fs.GroupSource rootGroupCache map[string]fstree.GroupSource
currentUserCache *User currentUserCache *User
// API response cache // API response cache
@ -57,10 +57,10 @@ func NewClient(gitlabUrl string, gitlabToken string, p GitlabClientConfig) (*git
return gitlabClient, nil return gitlabClient, nil
} }
func (c *gitlabClient) FetchRootGroupContent() (map[string]fs.GroupSource, error) { func (c *gitlabClient) FetchRootGroupContent() (map[string]fstree.GroupSource, error) {
// use cached values if available // use cached values if available
if c.rootGroupCache == nil { if c.rootGroupCache == nil {
rootGroupCache := make(map[string]fs.GroupSource) rootGroupCache := make(map[string]fstree.GroupSource)
// fetch root groups // fetch root groups
for _, gid := range c.GroupIDs { for _, gid := range c.GroupIDs {
@ -92,7 +92,7 @@ func (c *gitlabClient) FetchRootGroupContent() (map[string]fs.GroupSource, error
return c.rootGroupCache, nil return c.rootGroupCache, nil
} }
func (c *gitlabClient) FetchGroupContent(gid uint64) (map[string]fs.GroupSource, map[string]fs.RepositorySource, error) { func (c *gitlabClient) FetchGroupContent(gid uint64) (map[string]fstree.GroupSource, map[string]fstree.RepositorySource, error) {
if slices.Contains[[]int, int](c.UserIDs, int(gid)) || (c.currentUserCache != nil && c.currentUserCache.ID == int(gid)) { if slices.Contains[[]int, int](c.UserIDs, int(gid)) || (c.currentUserCache != nil && c.currentUserCache.ID == int(gid)) {
// gid is a user // gid is a user
user, err := c.fetchUser(int(gid)) user, err := c.fetchUser(int(gid))

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"sync" "sync"
"github.com/badjware/gitlabfs/fs" "github.com/badjware/gitlabfs/fstree"
"github.com/xanzy/go-gitlab" "github.com/xanzy/go-gitlab"
) )
@ -15,8 +15,8 @@ type Group struct {
mux sync.Mutex mux sync.Mutex
// group content cache // group content cache
groupCache map[string]fs.GroupSource groupCache map[string]fstree.GroupSource
projectCache map[string]fs.RepositorySource projectCache map[string]fstree.RepositorySource
} }
func (g *Group) GetGroupID() uint64 { func (g *Group) GetGroupID() uint64 {
@ -58,15 +58,15 @@ func (c *gitlabClient) fetchGroup(gid int) (*Group, error) {
return &newGroup, nil return &newGroup, nil
} }
func (c *gitlabClient) fetchGroupContent(group *Group) (map[string]fs.GroupSource, map[string]fs.RepositorySource, error) { func (c *gitlabClient) fetchGroupContent(group *Group) (map[string]fstree.GroupSource, map[string]fstree.RepositorySource, error) {
group.mux.Lock() group.mux.Lock()
defer group.mux.Unlock() defer group.mux.Unlock()
// Get cached data if available // Get cached data if available
// TODO: cache cache invalidation? // TODO: cache cache invalidation?
if group.groupCache == nil || group.projectCache == nil { if group.groupCache == nil || group.projectCache == nil {
groupCache := make(map[string]fs.GroupSource) groupCache := make(map[string]fstree.GroupSource)
projectCache := make(map[string]fs.RepositorySource) projectCache := make(map[string]fstree.RepositorySource)
// List subgroups in path // List subgroups in path
ListGroupsOpt := &gitlab.ListSubgroupsOptions{ ListGroupsOpt := &gitlab.ListSubgroupsOptions{

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"sync" "sync"
"github.com/badjware/gitlabfs/fs" "github.com/badjware/gitlabfs/fstree"
"github.com/xanzy/go-gitlab" "github.com/xanzy/go-gitlab"
) )
@ -15,7 +15,7 @@ type User struct {
mux sync.Mutex mux sync.Mutex
// user content cache // user content cache
projectCache map[string]fs.RepositorySource projectCache map[string]fstree.RepositorySource
} }
func (u *User) GetGroupID() uint64 { func (u *User) GetGroupID() uint64 {
@ -72,14 +72,14 @@ func (c *gitlabClient) fetchCurrentUser() (*User, error) {
return c.currentUserCache, nil return c.currentUserCache, nil
} }
func (c *gitlabClient) fetchUserContent(user *User) (map[string]fs.GroupSource, map[string]fs.RepositorySource, error) { func (c *gitlabClient) fetchUserContent(user *User) (map[string]fstree.GroupSource, map[string]fstree.RepositorySource, error) {
user.mux.Lock() user.mux.Lock()
defer user.mux.Unlock() defer user.mux.Unlock()
// Get cached data if available // Get cached data if available
// TODO: cache cache invalidation? // TODO: cache cache invalidation?
if user.projectCache == nil { if user.projectCache == nil {
projectCache := make(map[string]fs.RepositorySource) projectCache := make(map[string]fstree.RepositorySource)
// Fetch the user repositories // Fetch the user repositories
listProjectOpt := &gitlab.ListProjectsOptions{ listProjectOpt := &gitlab.ListProjectsOptions{
@ -105,5 +105,5 @@ func (c *gitlabClient) fetchUserContent(user *User) (map[string]fs.GroupSource,
user.projectCache = projectCache user.projectCache = projectCache
} }
return make(map[string]fs.GroupSource), user.projectCache, nil return make(map[string]fstree.GroupSource), user.projectCache, nil
} }

View File

@ -8,7 +8,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/badjware/gitlabfs/fs" "github.com/badjware/gitlabfs/fstree"
"github.com/badjware/gitlabfs/git" "github.com/badjware/gitlabfs/git"
"github.com/badjware/gitlabfs/gitlab" "github.com/badjware/gitlabfs/gitlab"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
@ -178,10 +178,10 @@ func main() {
gitlabClient, _ := gitlab.NewClient(config.Gitlab.URL, config.Gitlab.Token, *GitlabClientConfig) gitlabClient, _ := gitlab.NewClient(config.Gitlab.URL, config.Gitlab.Token, *GitlabClientConfig)
// Start the filesystem // Start the filesystem
err = fs.Start( err = fstree.Start(
mountpoint, mountpoint,
parsedMountoptions, parsedMountoptions,
&fs.FSParam{GitImplementation: gitClient, GitPlatform: gitlabClient}, &fstree.FSParam{GitImplementation: gitClient, GitPlatform: gitlabClient},
*debug, *debug,
) )
if err != nil { if err != nil {