MCPcopy Create free account
hub / github.com/MG-RAST/Shock / UpdateVersion

Method UpdateVersion

shock-server/node/update.go:553–584  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

551}
552
553func (node *Node) UpdateVersion() (err error) {
554 h := md5.New()
555 version := node.Id
556 versionParts := make(map[string]string)
557 partMap := map[string]interface{}{"file_ver": node.File, "indexes_ver": node.Indexes, "attributes_ver": node.Attributes, "acl_ver": node.Acl}
558
559 // need to keep map ordered
560 partKeys := []string{}
561 for k, _ := range partMap {
562 partKeys = append(partKeys, k)
563 }
564 sort.Strings(partKeys)
565
566 for _, k := range partKeys {
567 j, jerr := json.Marshal(partMap[k])
568 if jerr != nil {
569 err = fmt.Errorf("(json.Marshal) %s", err.Error())
570 return
571 }
572 // need to sort bytes to deal with unordered json
573 sj := SortByteArray(j)
574 h.Write(sj)
575 sum := fmt.Sprintf("%x", h.Sum(nil))
576 versionParts[k] = sum
577 version = version + sum
578 h.Reset()
579 }
580 h.Write([]byte(version))
581 node.Version = fmt.Sprintf("%x", h.Sum(nil))
582 node.VersionParts = versionParts
583 return
584}

Callers 1

SaveMethod · 0.95

Calls 3

SortByteArrayFunction · 0.85
ErrorMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected