From 0c647a692f2ebfbca1a09964932167c4a3e7de4a Mon Sep 17 00:00:00 2001 From: Massaki Archambault Date: Sun, 5 May 2024 16:23:07 -0400 Subject: [PATCH] rename fs package to fstree to avoid collision with go-fuse --- {fs => fstree}/group.go | 2 +- {fs => fstree}/refresh.go | 2 +- {fs => fstree}/repository.go | 12 ++++++------ {fs => fstree}/root.go | 2 +- gitlab/client.go | 10 +++++----- gitlab/group.go | 12 ++++++------ gitlab/user.go | 10 +++++----- main.go | 6 +++--- 8 files changed, 28 insertions(+), 28 deletions(-) rename {fs => fstree}/group.go (99%) rename {fs => fstree}/refresh.go (98%) rename {fs => fstree}/repository.go (78%) rename {fs => fstree}/root.go (99%) diff --git a/fs/group.go b/fstree/group.go similarity index 99% rename from fs/group.go rename to fstree/group.go index 9c0b59e..de0978f 100644 --- a/fs/group.go +++ b/fstree/group.go @@ -1,4 +1,4 @@ -package fs +package fstree import ( "context" diff --git a/fs/refresh.go b/fstree/refresh.go similarity index 98% rename from fs/refresh.go rename to fstree/refresh.go index 02bdae6..71cfdcc 100644 --- a/fs/refresh.go +++ b/fstree/refresh.go @@ -1,4 +1,4 @@ -package fs +package fstree import ( "context" diff --git a/fs/repository.go b/fstree/repository.go similarity index 78% rename from fs/repository.go rename to fstree/repository.go index 046183a..d37fd3d 100644 --- a/fs/repository.go +++ b/fstree/repository.go @@ -1,4 +1,4 @@ -package fs +package fstree import ( "context" @@ -7,7 +7,7 @@ import ( "github.com/hanwen/go-fuse/v2/fs" ) -type RepositoryNode struct { +type repositoryNode struct { fs.Inode param *FSParam @@ -22,10 +22,10 @@ type RepositorySource 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) { - node := &RepositoryNode{ +func newRepositoryNodeFromSource(source RepositorySource, param *FSParam) (*repositoryNode, error) { + node := &repositoryNode{ param: param, source: source, } @@ -34,7 +34,7 @@ func newRepositoryNodeFromSource(source RepositorySource, param *FSParam) (*Repo 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 // TODO: cleanup localRepositoryPath, _ := n.param.GitImplementation.CloneOrPull(n.source.GetCloneURL(), int(n.source.GetRepositoryID()), n.source.GetDefaultBranch()) diff --git a/fs/root.go b/fstree/root.go similarity index 99% rename from fs/root.go rename to fstree/root.go index 2155bee..5159ca9 100644 --- a/fs/root.go +++ b/fstree/root.go @@ -1,4 +1,4 @@ -package fs +package fstree import ( "context" diff --git a/gitlab/client.go b/gitlab/client.go index 716e76f..ee95af3 100644 --- a/gitlab/client.go +++ b/gitlab/client.go @@ -4,7 +4,7 @@ import ( "fmt" "slices" - "github.com/badjware/gitlabfs/fs" + "github.com/badjware/gitlabfs/fstree" "github.com/xanzy/go-gitlab" ) @@ -27,7 +27,7 @@ type gitlabClient struct { client *gitlab.Client // root group cache - rootGroupCache map[string]fs.GroupSource + rootGroupCache map[string]fstree.GroupSource currentUserCache *User // API response cache @@ -57,10 +57,10 @@ func NewClient(gitlabUrl string, gitlabToken string, p GitlabClientConfig) (*git 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 if c.rootGroupCache == nil { - rootGroupCache := make(map[string]fs.GroupSource) + rootGroupCache := make(map[string]fstree.GroupSource) // fetch root groups for _, gid := range c.GroupIDs { @@ -92,7 +92,7 @@ func (c *gitlabClient) FetchRootGroupContent() (map[string]fs.GroupSource, error 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)) { // gid is a user user, err := c.fetchUser(int(gid)) diff --git a/gitlab/group.go b/gitlab/group.go index 90fae26..89d3b3d 100644 --- a/gitlab/group.go +++ b/gitlab/group.go @@ -4,7 +4,7 @@ import ( "fmt" "sync" - "github.com/badjware/gitlabfs/fs" + "github.com/badjware/gitlabfs/fstree" "github.com/xanzy/go-gitlab" ) @@ -15,8 +15,8 @@ type Group struct { mux sync.Mutex // group content cache - groupCache map[string]fs.GroupSource - projectCache map[string]fs.RepositorySource + groupCache map[string]fstree.GroupSource + projectCache map[string]fstree.RepositorySource } func (g *Group) GetGroupID() uint64 { @@ -58,15 +58,15 @@ func (c *gitlabClient) fetchGroup(gid int) (*Group, error) { 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() defer group.mux.Unlock() // Get cached data if available // TODO: cache cache invalidation? if group.groupCache == nil || group.projectCache == nil { - groupCache := make(map[string]fs.GroupSource) - projectCache := make(map[string]fs.RepositorySource) + groupCache := make(map[string]fstree.GroupSource) + projectCache := make(map[string]fstree.RepositorySource) // List subgroups in path ListGroupsOpt := &gitlab.ListSubgroupsOptions{ diff --git a/gitlab/user.go b/gitlab/user.go index 7b6de4e..480e35e 100644 --- a/gitlab/user.go +++ b/gitlab/user.go @@ -4,7 +4,7 @@ import ( "fmt" "sync" - "github.com/badjware/gitlabfs/fs" + "github.com/badjware/gitlabfs/fstree" "github.com/xanzy/go-gitlab" ) @@ -15,7 +15,7 @@ type User struct { mux sync.Mutex // user content cache - projectCache map[string]fs.RepositorySource + projectCache map[string]fstree.RepositorySource } func (u *User) GetGroupID() uint64 { @@ -72,14 +72,14 @@ func (c *gitlabClient) fetchCurrentUser() (*User, error) { 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() defer user.mux.Unlock() // Get cached data if available // TODO: cache cache invalidation? if user.projectCache == nil { - projectCache := make(map[string]fs.RepositorySource) + projectCache := make(map[string]fstree.RepositorySource) // Fetch the user repositories listProjectOpt := &gitlab.ListProjectsOptions{ @@ -105,5 +105,5 @@ func (c *gitlabClient) fetchUserContent(user *User) (map[string]fs.GroupSource, user.projectCache = projectCache } - return make(map[string]fs.GroupSource), user.projectCache, nil + return make(map[string]fstree.GroupSource), user.projectCache, nil } diff --git a/main.go b/main.go index 8983393..2ef9960 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,7 @@ import ( "path/filepath" "strings" - "github.com/badjware/gitlabfs/fs" + "github.com/badjware/gitlabfs/fstree" "github.com/badjware/gitlabfs/git" "github.com/badjware/gitlabfs/gitlab" "gopkg.in/yaml.v2" @@ -178,10 +178,10 @@ func main() { gitlabClient, _ := gitlab.NewClient(config.Gitlab.URL, config.Gitlab.Token, *GitlabClientConfig) // Start the filesystem - err = fs.Start( + err = fstree.Start( mountpoint, parsedMountoptions, - &fs.FSParam{GitImplementation: gitClient, GitPlatform: gitlabClient}, + &fstree.FSParam{GitImplementation: gitClient, GitPlatform: gitlabClient}, *debug, ) if err != nil {