Skip to content

Commit

Permalink
Fix Mentix data cloning bug (#1457)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-WWU-IT authored Feb 12, 2021
1 parent d270f61 commit 23ecb86
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/mentix-clone-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Cloning of internal mesh data lost some values

This update fixes a bug in Mentix that caused some (non-critical) values to be lost during data cloning that happens internally.

https://github.com/cs3org/reva/pull/1457
4 changes: 2 additions & 2 deletions pkg/mentix/connectors/localfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func (connector *LocalFileConnector) RetrieveMeshData() (*meshdata.MeshData, err
connector.setSiteTypes(meshData)

meshData.InferMissingData()

return meshData, nil
}

Expand Down Expand Up @@ -145,8 +146,7 @@ func (connector *LocalFileConnector) unmergeData(meshData *meshdata.MeshData, up

func (connector *LocalFileConnector) authorizeData(meshData *meshdata.MeshData, updatedData *meshdata.MeshData, authorize bool) error {
for _, placeholderSite := range updatedData.Sites {
// The site ID is stored in the updated site's name
if site := meshData.FindSite(placeholderSite.Name); site != nil {
if site := meshData.FindSite(placeholderSite.ID); site != nil {
if authorize {
meshdata.SetPropertyValue(&site.Properties, meshdata.PropertyAuthorized, "true")
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/mentix/exchangers/importers/adminapi/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func decodeAdminQueryData(data []byte) (*meshdata.MeshData, error) {
if value, ok := jsonData["id"]; ok {
if id, ok := value.(string); ok {
site := &meshdata.Site{}
site.Name = id // Store the provided site ID in the site's name
site.ID = id // We only need to store the ID of the site

meshData := &meshdata.MeshData{Sites: []*meshdata.Site{site}}
return meshData, nil
Expand Down
23 changes: 11 additions & 12 deletions pkg/mentix/meshdata/meshdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
package meshdata

import (
"bytes"
"encoding/gob"
"encoding/json"
"fmt"
"reflect"
"strings"
)

Expand Down Expand Up @@ -196,10 +199,13 @@ func (meshData *MeshData) FromJSON(data string) error {
func (meshData *MeshData) Clone() *MeshData {
clone := &MeshData{}

// To avoid any "deep copy" packages, use JSON en- and decoding instead
data, err := meshData.ToJSON()
if err == nil {
if err := clone.FromJSON(data); err != nil {
// To avoid any "deep copy" packages, use gob en- and decoding instead
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
dec := gob.NewDecoder(&buf)

if err := enc.Encode(meshData); err == nil {
if err := dec.Decode(clone); err != nil {
// In case of an error, clear the data
clone.Clear()
}
Expand All @@ -210,14 +216,7 @@ func (meshData *MeshData) Clone() *MeshData {

// Compare checks whether the stored data equals the data of another MeshData object.
func (meshData *MeshData) Compare(other *MeshData) bool {
if other == nil {
return false
}

// To avoid cumbersome comparisons, just compare the JSON-encoded data
json1, _ := meshData.ToJSON()
json2, _ := other.ToJSON()
return json1 == json2
return reflect.DeepEqual(meshData, other)
}

// New returns a new (empty) MeshData object.
Expand Down

0 comments on commit 23ecb86

Please sign in to comment.