Fix config_diff panics when old config or new config is empty

Fixes #190
This commit is contained in:
Miao Wang 2023-04-18 20:31:50 +08:00
parent c3b742c2a8
commit 45099fc7d3

View File

@ -53,6 +53,7 @@ func diffMirrorConfig(oldList, newList []mirrorConfig) []mirrorCfgTrans {
sort.Sort(sortableMirrorList(oList)) sort.Sort(sortableMirrorList(oList))
sort.Sort(sortableMirrorList(nList)) sort.Sort(sortableMirrorList(nList))
if len(oList) != 0 && len(nList) != 0 {
// insert a tail node to both lists // insert a tail node to both lists
// as the maximum node // as the maximum node
lastOld, lastNew := oList[len(oList)-1], nList[len(nList)-1] lastOld, lastNew := oList[len(oList)-1], nList[len(nList)-1]
@ -83,6 +84,14 @@ func diffMirrorConfig(oldList, newList []mirrorConfig) []mirrorCfgTrans {
j++ j++
} }
} }
} else {
for i := 0; i < len(oList); i++ {
operations = append(operations, mirrorCfgTrans{diffDelete, oList[i]})
}
for i := 0; i < len(nList); i++ {
operations = append(operations, mirrorCfgTrans{diffAdd, nList[i]})
}
}
return operations return operations
} }