Fix remaining zone.Remove* functions

Fix the remove function and make them more like zone.Remove()
This commit is contained in:
Miek Gieben 2013-05-05 21:52:21 +02:00
parent 6cb4f9cf69
commit 9a80799666
2 changed files with 12 additions and 0 deletions

View File

@ -182,6 +182,11 @@ z2.miek.nl. IN NSEC miek.nl. TXT RRSIG NSEC`
t.Log("Not all names correct")
t.Fail()
}
z.RemoveName("z2.miek.nl.")
if z.sortedNames[0] != "z1.miek.nl." || z.sortedNames[1] != "z3.miek.nl." {
t.Logf("Not all names correct %v\n", z.sortedNames)
t.Fail()
}
}
func TestDomainName(t *testing.T) {

View File

@ -284,6 +284,13 @@ func (z *Zone) RemoveName(s string) error {
z.ModTime = time.Now().UTC()
defer z.Unlock()
delete(z.Names, s)
i := sort.SearchStrings(z.sortedNames, s)
if z.sortedNames[i] == s {
copy(z.sortedNames[i:], z.sortedNames[i+1:])
z.sortedNames[len(z.sortedNames)-1] = ""
z.sortedNames = z.sortedNames[:len(z.sortedNames)-1]
}
if len(s) > 1 && s[0] == '*' && s[1] == '.' {
z.Wildcard--
if z.Wildcard < 0 {