aboutsummaryrefslogtreecommitdiffstats
path: root/lib/xdsserver/folders.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-12-16 00:10:14 +0100
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-12-16 00:10:14 +0100
commit285332c351777b74abca638b8b2a2cde3c68edc6 (patch)
treece52d6d347f23a944520a6b239f8099de75e1a41 /lib/xdsserver/folders.go
parent963931e04d44a5b40d38817163f52f56241a9f33 (diff)
Fixed and improved events management.
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'lib/xdsserver/folders.go')
-rw-r--r--lib/xdsserver/folders.go52
1 files changed, 16 insertions, 36 deletions
diff --git a/lib/xdsserver/folders.go b/lib/xdsserver/folders.go
index 7a45bbd..b0c198a 100644
--- a/lib/xdsserver/folders.go
+++ b/lib/xdsserver/folders.go
@@ -216,6 +216,7 @@ func (f *Folders) Add(newF xsapiv1.FolderConfig) (*xsapiv1.FolderConfig, error)
// CreateUpdate creates or update a folder
func (f *Folders) createUpdate(newF xsapiv1.FolderConfig, create bool, initial bool) (*xsapiv1.FolderConfig, error) {
+ var err error
fcMutex.Lock()
defer fcMutex.Unlock()
@@ -269,12 +270,21 @@ func (f *Folders) createUpdate(newF xsapiv1.FolderConfig, create bool, initial b
// Normalize path (needed for Windows path including bashlashes)
newF.ClientPath = common.PathNormalize(newF.ClientPath)
- // Add new folder
- newFolder, err := fld.Add(newF)
- if err != nil {
- newF.Status = xsapiv1.StatusErrorConfig
- log.Printf("ERROR Adding folder: %v\n", err)
- return newFolder, err
+ var newFolder *xsapiv1.FolderConfig
+ if create {
+ // Add folder
+ if newFolder, err = fld.Add(newF); err != nil {
+ newF.Status = xsapiv1.StatusErrorConfig
+ log.Printf("ERROR Adding folder: %v\n", err)
+ return newFolder, err
+ }
+ } else {
+ // Just update project config
+ if newFolder, err = fld.Setup(newF); err != nil {
+ newF.Status = xsapiv1.StatusErrorConfig
+ log.Printf("ERROR Updating folder: %v\n", err)
+ return newFolder, err
+ }
}
// Add to folders list
@@ -287,13 +297,6 @@ func (f *Folders) createUpdate(newF xsapiv1.FolderConfig, create bool, initial b
}
}
- // Register event change callback
- for _, rcb := range f.registerCB {
- if err := fld.RegisterEventChange(rcb.cb, rcb.data); err != nil {
- return newFolder, err
- }
- }
-
// Force sync after creation
// (need to defer to be sure that WS events will arrive after HTTP creation reply)
go func() {
@@ -379,29 +382,6 @@ func (f *Folders) Update(id string, cfg xsapiv1.FolderConfig) (*xsapiv1.FolderCo
return fld, err
}
-// RegisterEventChange requests registration for folder event change
-func (f *Folders) RegisterEventChange(id string, cb *FolderEventCB, data *FolderEventCBData) error {
-
- flds := make(map[string]*IFOLDER)
- if id != "" {
- // Register to a specific folder
- flds[id] = f.Get(id)
- } else {
- // Register to all folders
- flds = f.folders
- f.registerCB = append(f.registerCB, RegisteredCB{cb: cb, data: data})
- }
-
- for _, fld := range flds {
- err := (*fld).RegisterEventChange(cb, data)
- if err != nil {
- return err
- }
- }
-
- return nil
-}
-
// ForceSync Force the synchronization of a folder
func (f *Folders) ForceSync(id string) error {
fc := f.Get(id)