cli: fix check for synced replicas

If the expected replica count had exceeded the amount of seeds already
synced with the following message would appear:

    Not connected to any seeds for {rid}.

This is not true, since there are seeds that were already synced.

This is fixed by calculating the `synced` and `connected` nodes,
without the local peer in the set. This means that the check for
`synced.len() >= connected.len()` will get a hit and the function will
correctly return early.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny
2023-12-21 15:47:35 +00:00
parent 47a440a384
commit a3826f8daf
+9 -3
View File
@@ -397,15 +397,21 @@ fn announce_refs(
}
}
RepoSync::Replicas(replicas) => {
let synced = synced.collect::<Vec<_>>();
if synced.len() >= seeds.len() {
let synced = synced
.filter(|s| &s.nid != profile.id())
.collect::<Vec<_>>();
let connected = seeds
.connected()
.filter(|s| &s.nid != profile.id())
.collect::<Vec<_>>();
if synced.len() >= connected.len() {
term::success!(
"Nothing to announce, already in sync with network (see `rad sync status`)"
);
return Ok(());
}
// Replicas not counting our local replica.
let remotes = synced.iter().filter(|s| &s.nid != profile.id()).count();
let remotes = synced.len();
if remotes >= replicas {
term::success!("Nothing to announce, already in sync with {remotes} seed(s) (see `rad sync status`)");
return Ok(());