2020-12-27 07:23:00 +00:00
|
|
|
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
|
2020-12-27 07:23:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
2020-12-27 07:23:00 +00:00
|
|
|
node := &RepositoryNode{
|
2020-12-30 00:49:11 +00:00
|
|
|
param: param,
|
|
|
|
project: project,
|
2020-12-27 07:23:00 +00:00
|
|
|
}
|
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
|
2020-12-27 07:23:00 +00:00
|
|
|
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
|
2020-12-30 00:49:11 +00:00
|
|
|
localRepoLoc, _ := n.param.Git.CloneOrPull(n.project.CloneURL, n.project.ID, "master")
|
2020-12-29 02:37:18 +00:00
|
|
|
|
|
|
|
return []byte(localRepoLoc), 0
|
2020-12-27 07:23:00 +00:00
|
|
|
}
|