Fix zone.Remove

This commit is contained in:
Miek Gieben 2012-10-15 09:31:14 +02:00
parent b8b471c012
commit 6d968caf7c
1 changed files with 15 additions and 6 deletions

21
zone.go
View File

@ -273,30 +273,39 @@ func (z *Zone) Remove(r RR) error {
remove = true
}
}
if remove {
// If every Signature of the covering type is removed, removed the type from the map
if len(zd.Value.(*ZoneData).RR[sigtype]) == 0 {
delete(zd.Value.(*ZoneData).RR, sigtype)
}
}
default:
for i, zr := range zd.Value.(*ZoneData).RR[t] {
// Matching RR
if r == zr {
if len(zd.Value.(*ZoneData).RR[t]) == 0 {
zd.Value.(*ZoneData).RR[t] = nil
}
println("removing", i)
zd.Value.(*ZoneData).RR[t] = append(zd.Value.(*ZoneData).RR[t][:i], zd.Value.(*ZoneData).RR[t][i+1:]...)
remove = true
}
}
if remove {
// If every RR of this type is removed, removed the type from the map
if len(zd.Value.(*ZoneData).RR[t]) == 0 {
delete(zd.Value.(*ZoneData).RR, t)
}
}
}
if !remove {
return nil
}
if len(r.Header().Name) > 1 && r.Header().Name[0] == '*' && r.Header().Name[1] == '.' {
z.Wildcard--
if z.Wildcard < 0 {
z.Wildcard = 0
}
}
println(len(zd.Value.(*ZoneData).RR), len(zd.Value.(*ZoneData).Signatures))
if len(zd.Value.(*ZoneData).RR) == 0 && len(zd.Value.(*ZoneData).Signatures) == 0 {
println("REMOVING")
// Entire node is empty, remove it from the Radix tree
z.Radix.Remove(key)
}
return nil