gitforgefs/fs/repository.go

36 lines
855 B
Go
Raw Normal View History

package fs
import (
"context"
"syscall"
"github.com/badjware/gitlabfs/gitlab"
"github.com/hanwen/go-fuse/v2/fs"
)
type RepositoryNode struct {
fs.Inode
2020-12-30 00:49:11 +00:00
param *FSParam
project *gitlab.Project
}
// Ensure we are implementing the NodeReaddirer interface
var _ = (fs.NodeReadlinker)((*RepositoryNode)(nil))
2020-12-30 00:49:11 +00:00
func newRepositoryNode(project *gitlab.Project, param *FSParam) (*RepositoryNode, error) {
node := &RepositoryNode{
2020-12-30 00:49:11 +00:00
param: param,
project: project,
}
2020-12-29 02:37:18 +00:00
// Passthrough the error if there is one, nothing to add here
// Errors on clone/pull are non-fatal
return node, nil
}
func (n *RepositoryNode) Readlink(ctx context.Context) ([]byte, syscall.Errno) {
2020-12-29 02:37:18 +00:00
// Create the local copy of the repo
localRepoLoc, _ := n.param.Git.CloneOrPull(n.project.CloneURL, n.project.ID, n.project.DefaultBranch)
2020-12-29 02:37:18 +00:00
return []byte(localRepoLoc), 0
}