3 import "github.com/iotbzh/xds-agent/lib/syncthing"
7 // IPROJECT interface implementation for syncthing projects
10 type STProject struct {
16 // NewProjectST Create a new instance of STProject
17 func NewProjectST(ctx *Context, svr *XdsServer) *STProject {
21 folder: &FolderConfig{},
27 func (p *STProject) Add(cfg ProjectConfig) (*ProjectConfig, error) {
30 err = p.server.FolderAdd(p.server.ProjectToFolder(cfg), p.folder)
34 svrPrj := p.GetProject()
36 // Declare project into local Syncthing
37 p.SThg.FolderChange(st.FolderChangeArg{
40 RelativePath: cfg.ClientPath,
41 SyncThingID: p.server.ServerConfig.Builder.SyncThingID,
48 func (p *STProject) Delete() error {
49 return p.server.FolderDelete(p.folder.ID)
52 // GetProject Get public part of project config
53 func (p *STProject) GetProject() *ProjectConfig {
54 prj := p.server.FolderToProject(*p.folder)
55 prj.ServerID = p.server.ID
59 // SetProject Set project config
60 func (p *STProject) SetProject(prj ProjectConfig) *ProjectConfig {
62 p.folder = p.server.ProjectToFolder(prj)
66 // GetServer Get the XdsServer that holds this project
67 func (p *STProject) GetServer() *XdsServer {
72 // GetFullPath returns the full path of a directory (from server POV)
73 func (p *STProject) GetFullPath(dir string) string {
76 return p.folder.DataSTProject.ServerPath
78 return filepath.Join(p.folder.DataSTProject.ServerPath, dir)
83 // Sync Force project files synchronization
84 func (p *STProject) Sync() error {
89 // IsInSync Check if project files are in-sync
90 func (p *STProject) IsInSync() (bool, error) {