X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=lib%2Fxdsserver%2Ffolder-pathmap.go;h=5b75ca16a8cc02c0b25861a9fd9374b8aaa23d60;hb=5dc2ff003106f0ced38caadb06033f24c792f9b9;hp=c5318de68e53a8d4b4bc95692e8cebfb93daebbd;hpb=2f7828d01f4c4ca2909f95f098627cd5475ed225;p=src%2Fxds%2Fxds-server.git diff --git a/lib/xdsserver/folder-pathmap.go b/lib/xdsserver/folder-pathmap.go index c5318de..5b75ca1 100644 --- a/lib/xdsserver/folder-pathmap.go +++ b/lib/xdsserver/folder-pathmap.go @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2017-2018 "IoT.bzh" + * Author Sebastien Douheret + * + * 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 ( @@ -7,8 +24,8 @@ 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" ) @@ -17,14 +34,14 @@ import ( // 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, }, } @@ -42,6 +59,12 @@ func (f *PathMap) NewUID(suffix string) string { // 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") } @@ -63,10 +86,10 @@ func (f *PathMap) Add(cfg xsapiv1.FolderConfig) (*xsapiv1.FolderConfig, error) { 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 != "" { @@ -99,30 +122,30 @@ func (f *PathMap) Add(cfg xsapiv1.FolderConfig) (*xsapiv1.FolderConfig, error) { } } - 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 @@ -130,10 +153,10 @@ func (f *PathMap) ConvPathCli2Svr(s string) string { // 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 @@ -147,21 +170,11 @@ func (f *PathMap) Remove() error { // 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