diff --git a/changelog/unreleased/mentix-clone-fix.md b/changelog/unreleased/mentix-clone-fix.md new file mode 100644 index 0000000000..d5ab1f3232 --- /dev/null +++ b/changelog/unreleased/mentix-clone-fix.md @@ -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 diff --git a/pkg/mentix/connectors/localfile.go b/pkg/mentix/connectors/localfile.go index cbe3da9605..6c154adc2c 100755 --- a/pkg/mentix/connectors/localfile.go +++ b/pkg/mentix/connectors/localfile.go @@ -79,6 +79,7 @@ func (connector *LocalFileConnector) RetrieveMeshData() (*meshdata.MeshData, err connector.setSiteTypes(meshData) meshData.InferMissingData() + return meshData, nil } @@ -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 { diff --git a/pkg/mentix/exchangers/importers/adminapi/query.go b/pkg/mentix/exchangers/importers/adminapi/query.go index 36c2265849..cb7a65a198 100755 --- a/pkg/mentix/exchangers/importers/adminapi/query.go +++ b/pkg/mentix/exchangers/importers/adminapi/query.go @@ -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 diff --git a/pkg/mentix/meshdata/meshdata.go b/pkg/mentix/meshdata/meshdata.go index 9ab0ecdf4a..05289b72d1 100644 --- a/pkg/mentix/meshdata/meshdata.go +++ b/pkg/mentix/meshdata/meshdata.go @@ -19,8 +19,11 @@ package meshdata import ( + "bytes" + "encoding/gob" "encoding/json" "fmt" + "reflect" "strings" ) @@ -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() } @@ -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.