check rule conflict

Signed-off-by: Ziming Zhang <zziming@vmware.com>
Change-Id: I95f7e683b30fa6059b5bb49a2fc8f78dd7276079
This commit is contained in:
Ziming Zhang 2019-08-07 17:52:47 +08:00
parent 3b62addc76
commit 730d95edc8

View File

@ -1,7 +1,6 @@
package api
import (
"crypto/sha256"
"encoding/json"
"errors"
"fmt"
@ -242,12 +241,10 @@ func (r *RetentionAPI) checkRuleConflict(p *policy.Metadata) error {
tid := rule.ID
rule.ID = 0
bs, _ := json.Marshal(rule)
s := sha256.New()
h := s.Sum(bs)
if old, exists := temp[string(h)]; exists {
if old, exists := temp[string(bs)]; exists {
return fmt.Errorf("rule %d is conflict with rule %d", n, old)
}
temp[string(h)] = tid
temp[string(bs)] = tid
rule.ID = tid
}
return nil