+/*
+ * Copyright (C) 2017-2018 "IoT.bzh"
+ * Author Sebastien Douheret <sebastien@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package xdsserver
import (
"path/filepath"
"strings"
- common "github.com/iotbzh/xds-common/golib"
- "github.com/iotbzh/xds-server/lib/xsapiv1"
+ common "gerrit.automotivelinux.org/gerrit/src/xds/xds-common.git"
+ "gerrit.automotivelinux.org/gerrit/src/xds/xds-server.git/lib/xsapiv1"
uuid "github.com/satori/go.uuid"
)
// PathMap .
type PathMap struct {
*Context
- config xsapiv1.FolderConfig
+ fConfig xsapiv1.FolderConfig
}
// NewFolderPathMap Create a new instance of PathMap
func NewFolderPathMap(ctx *Context) *PathMap {
f := PathMap{
Context: ctx,
- config: xsapiv1.FolderConfig{
+ fConfig: xsapiv1.FolderConfig{
Status: xsapiv1.StatusDisable,
},
}
// Add a new folder
func (f *PathMap) Add(cfg xsapiv1.FolderConfig) (*xsapiv1.FolderConfig, error) {
+ return f.Setup(cfg)
+}
+
+// Setup Setup local project config
+func (f *PathMap) Setup(cfg xsapiv1.FolderConfig) (*xsapiv1.FolderConfig, error) {
+
if cfg.DataPathMap.ServerPath == "" {
return nil, fmt.Errorf("ServerPath must be set")
}
return nil, fmt.Errorf("ServerPath directory is not accessible: %s", dir)
}
- f.config = cfg
- f.config.RootPath = dir
- f.config.DataPathMap.ServerPath = dir
- f.config.IsInSync = true
+ f.fConfig = cfg
+ f.fConfig.RootPath = dir
+ f.fConfig.DataPathMap.ServerPath = dir
+ f.fConfig.IsInSync = true
// Verify file created by XDS agent when needed
if cfg.DataPathMap.CheckFile != "" {
}
}
- f.config.Status = xsapiv1.StatusEnable
+ f.fConfig.Status = xsapiv1.StatusEnable
- return &f.config, nil
+ return &f.fConfig, nil
}
// GetConfig Get public part of folder config
func (f *PathMap) GetConfig() xsapiv1.FolderConfig {
- return f.config
+ return f.fConfig
}
// GetFullPath returns the full path of a directory (from server POV)
func (f *PathMap) GetFullPath(dir string) string {
if &dir == nil {
- return f.config.DataPathMap.ServerPath
+ return f.fConfig.DataPathMap.ServerPath
}
- return filepath.Join(f.config.DataPathMap.ServerPath, dir)
+ return filepath.Join(f.fConfig.DataPathMap.ServerPath, dir)
}
// ConvPathCli2Svr Convert path from Client to Server
func (f *PathMap) ConvPathCli2Svr(s string) string {
- if f.config.ClientPath != "" && f.config.DataPathMap.ServerPath != "" {
+ if f.fConfig.ClientPath != "" && f.fConfig.DataPathMap.ServerPath != "" {
return strings.Replace(s,
- f.config.ClientPath,
- f.config.DataPathMap.ServerPath,
+ f.fConfig.ClientPath,
+ f.fConfig.DataPathMap.ServerPath,
-1)
}
return s
// ConvPathSvr2Cli Convert path from Server to Client
func (f *PathMap) ConvPathSvr2Cli(s string) string {
- if f.config.ClientPath != "" && f.config.DataPathMap.ServerPath != "" {
+ if f.fConfig.ClientPath != "" && f.fConfig.DataPathMap.ServerPath != "" {
return strings.Replace(s,
- f.config.DataPathMap.ServerPath,
- f.config.ClientPath,
+ f.fConfig.DataPathMap.ServerPath,
+ f.fConfig.ClientPath,
-1)
}
return s
// Update update some fields of a folder
func (f *PathMap) Update(cfg xsapiv1.FolderConfig) (*xsapiv1.FolderConfig, error) {
- if f.config.ID != cfg.ID {
+ if f.fConfig.ID != cfg.ID {
return nil, fmt.Errorf("Invalid id")
}
- f.config = cfg
- return &f.config, nil
-}
-
-// RegisterEventChange requests registration for folder change event
-func (f *PathMap) RegisterEventChange(cb *FolderEventCB, data *FolderEventCBData) error {
- return nil
-}
-
-// UnRegisterEventChange remove registered callback
-func (f *PathMap) UnRegisterEventChange() error {
- return nil
+ f.fConfig = cfg
+ return &f.fConfig, nil
}
// Sync Force folder files synchronization