Skip to content

Commit

Permalink
Merge pull request #96 from erikh/fix-duplicate-record-when-renaming
Browse files Browse the repository at this point in the history
When replacing the record, don't try to edit it
  • Loading branch information
Erik Hollensbe authored Jul 26, 2021
2 parents 4c35426 + 24b6e0e commit 0ae2fb8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ test:
cargo test

test-integration:
ifneq (${SKIP},)
TOKEN=$$(cat test-token.txt) sudo -E bash -c "$$(which cargo) test --features integration-tests -j1 -- --skip '${SKIP}' --nocapture --test-threads 1"
else
TOKEN=$$(cat test-token.txt) sudo -E bash -c "$$(which cargo) test --features integration-tests -j1 -- --nocapture --test-threads 1"
endif

generate: central service

Expand Down
53 changes: 25 additions & 28 deletions src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use trust_dns_resolver::{

use trust_dns_server::{
authority::{AuthorityObject, Catalog},
client::rr::{Name, RData, Record, RecordType, RrKey},
client::rr::{LowerName, Name, RData, Record, RecordType, RrKey},
store::forwarder::ForwardAuthority,
store::{forwarder::ForwardConfig, in_memory::InMemoryAuthority},
};
Expand Down Expand Up @@ -162,17 +162,9 @@ fn upsert_address(
) {
let serial = authority.serial() + 1;
let records = authority.records_mut();
let key = records
.into_iter()
.map(|(key, _)| key)
.find(|key| key.name().into_name().unwrap().eq(&fqdn));

if let Some(key) = key {
let key = key.clone();
records
.get_mut(&key)
.replace(&mut Arc::new(RecordSet::new(&fqdn.clone(), rt, serial)));
}
let key = RrKey::new(LowerName::from(fqdn.clone()), rt);

records.remove(&key);

for rdata in rdatas {
if match rt {
Expand Down Expand Up @@ -228,7 +220,7 @@ fn set_ptr_record(
);
}

fn set_ip_record(
fn replace_ip_record(
authority: &mut RwLockWriteGuard<InMemoryAuthority>,
name: Name,
rt: RecordType,
Expand Down Expand Up @@ -538,12 +530,13 @@ impl ZTAuthority {
.authority
.read()
.expect("Could not get authority read lock");
let records = lock

let rs = lock
.records()
.get(&RrKey::new(name.clone().into(), rt))
.clone();

let ips = newips
let ips: Vec<IpAddr> = newips
.clone()
.into_iter()
.filter(|i| match i {
Expand All @@ -552,30 +545,34 @@ impl ZTAuthority {
})
.collect();

match records {
Some(records) => {
let records = records.records(false, SupportedAlgorithms::all());
match rs {
Some(rs) => {
let records = rs.records(false, SupportedAlgorithms::all());
if records.is_empty()
|| !records.into_iter().all(|r| rdatas.contains(r.rdata()))
{
drop(lock);
set_ip_record(
if !ips.is_empty() {
replace_ip_record(
&mut self.authority.write().expect("write lock"),
name.clone(),
rt,
ips,
);
}
}
}
None => {
drop(lock);
if !ips.is_empty() {
replace_ip_record(
&mut self.authority.write().expect("write lock"),
name.clone(),
rt,
ips,
);
}
}
None => {
drop(lock);
set_ip_record(
&mut self.authority.write().expect("write lock"),
name.clone(),
rt,
ips,
);
}
}
}
}
Expand Down

0 comments on commit 0ae2fb8

Please sign in to comment.