9 common "github.com/iotbzh/xds-common/golib"
12 // IFOLDER interface implementation for native/path mapping folders
19 // NewFolderPathMap Create a new instance of PathMap
20 func NewFolderPathMap() *PathMap {
26 func (f *PathMap) Add(cfg FolderConfig) (*FolderConfig, error) {
27 if cfg.DataPathMap.ServerPath == "" {
28 return nil, fmt.Errorf("ServerPath must be set")
32 dir := cfg.DataPathMap.ServerPath
33 if !common.Exists(dir) {
34 // try to create if not existing
35 if err := os.MkdirAll(dir, 0755); err != nil {
36 return nil, fmt.Errorf("Cannot create ServerPath directory: %s", dir)
39 if !common.Exists(dir) {
40 return nil, fmt.Errorf("ServerPath directory is not accessible: %s", dir)
42 file, err := ioutil.TempFile(dir, "xds_pathmap_check")
44 return nil, fmt.Errorf("ServerPath sanity check error: %s", err.Error())
46 defer os.Remove(file.Name())
48 msg := "sanity check PathMap Add folder"
49 n, err := file.Write([]byte(msg))
50 if err != nil || n != len(msg) {
51 return nil, fmt.Errorf("ServerPath sanity check error: %s", err.Error())
55 f.config.RootPath = cfg.DataPathMap.ServerPath
56 f.config.Status = StatusEnable
61 // GetConfig Get public part of folder config
62 func (f *PathMap) GetConfig() FolderConfig {
66 // GetFullPath returns the full path
67 func (f *PathMap) GetFullPath(dir string) string {
69 return f.config.DataPathMap.ServerPath
71 return filepath.Join(f.config.DataPathMap.ServerPath, dir)
75 func (f *PathMap) Remove() error {
80 // Sync Force folder files synchronization
81 func (f *PathMap) Sync() error {
85 // IsInSync Check if folder files are in-sync
86 func (f *PathMap) IsInSync() (bool, error) {