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"
|
|
|
|
)
|
|
|
|
|
2024-05-05 20:23:07 +00:00
|
|
|
type repositoryNode struct {
|
2020-12-27 07:23:00 +00:00
|
|
|
fs.Inode
|
2024-05-05 20:09:03 +00:00
|
|
|
param *FSParam
|
|
|
|
|
|
|
|
source RepositorySource
|
|
|
|
}
|
|
|
|
|
|
|
|
type RepositorySource interface {
|
|
|
|
// GetName() string
|
|
|
|
GetRepositoryID() uint64
|
|
|
|
GetCloneURL() string
|
|
|
|
GetDefaultBranch() string
|
2020-12-27 07:23:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure we are implementing the NodeReaddirer interface
|
2024-05-05 20:23:07 +00:00
|
|
|
var _ = (fs.NodeReadlinker)((*repositoryNode)(nil))
|
2020-12-27 07:23:00 +00:00
|
|
|
|
2024-05-05 20:23:07 +00:00
|
|
|
func newRepositoryNodeFromSource(source RepositorySource, param *FSParam) (*repositoryNode, error) {
|
|
|
|
node := &repositoryNode{
|
2024-05-05 20:09:03 +00:00
|
|
|
param: param,
|
|
|
|
source: source,
|
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
|
|
|
|
}
|
|
|
|
|
2024-05-05 20:23:07 +00:00
|
|
|
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
|
2024-05-05 20:09:03 +00:00
|
|
|
// TODO: cleanup
|
|
|
|
localRepositoryPath, _ := n.param.GitImplementation.CloneOrPull(n.source.GetCloneURL(), int(n.source.GetRepositoryID()), n.source.GetDefaultBranch())
|
2020-12-29 02:37:18 +00:00
|
|
|
|
2024-05-05 20:09:03 +00:00
|
|
|
return []byte(localRepositoryPath), 0
|
2020-12-27 07:23:00 +00:00
|
|
|
}
|