Skip to content

Commit b742ca8

Browse files
authored
Merge pull request #41 from silicon-heaven/crash-if-no-root-hp3-key
Crash if sites root node doesn't have an HP3 key
2 parents 66911b2 + 6b18e63 commit b742ca8

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

src/sites.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,12 +398,25 @@ pub(crate) async fn sites_task(
398398
shvclient::ClientEvent::Connected(shv_api_version) => {
399399
log::info!("Getting sites info");
400400

401-
let sites = RpcCall::new("sites", "getSites")
401+
let sites: Result<shvproto::Map, _> = RpcCall::new("sites", "getSites")
402402
.exec(&client_cmd_tx)
403403
.await;
404404

405405
let (sites_info, sub_hps) = match sites {
406406
Ok(sites) => {
407+
eprintln!("sites = '{:?}'", sites);
408+
if sites
409+
.get("_meta")
410+
.map(RpcValue::as_map)
411+
.and_then(|map| map.get("HP3"))
412+
.map(RpcValue::as_map)
413+
.and_then(|map| map.get("type"))
414+
.map(RpcValue::as_str)
415+
.is_none_or(|type_str| type_str != "HP3")
416+
{
417+
eprintln!("This site's _meta does NOT include an HP3 node. Refusing to continue. Add an HP3 node to the site's _meta, otherwise this HP instance will not be visible to parent HPs.");
418+
std::process::abort();
419+
}
407420
let sub_hps = collect_sub_hps(&[], &sites);
408421
let mut sites_info = collect_sites(&[], &sites);
409422
for (path, site_info) in &mut sites_info {
@@ -776,6 +789,14 @@ mod tests {
776789
cleanup_steps: &'a [Box<dyn TestStep<SitesTaskTestState>>],
777790
}
778791

792+
fn no_sites() -> RpcValue {
793+
RpcValue::from_cpon(r#"{
794+
"_meta":{
795+
"HP3":{"type": "HP3"}
796+
},
797+
}"#).unwrap()
798+
}
799+
779800
fn some_broker() -> RpcValue {
780801
RpcValue::from_cpon(r#"{
781802
"_meta":{
@@ -831,7 +852,7 @@ mod tests {
831852
name: "Empty sites",
832853
steps: &[
833854
Box::new(ClientEvent::Connected(shvclient::client::ShvApiVersion::V3)),
834-
Box::new(ExpectCall("sites", "getSites", Ok(shvproto::Map::new().into()))),
855+
Box::new(ExpectCall("sites", "getSites", Ok(no_sites()))),
835856
],
836857
starting_files: vec![],
837858
expected_file_paths: vec![],
@@ -881,7 +902,7 @@ mod tests {
881902
name: "Periodic sync",
882903
steps: &[
883904
Box::new(ClientEvent::Connected(shvclient::client::ShvApiVersion::V3)),
884-
Box::new(ExpectCall("sites", "getSites", Ok(shvproto::Map::new().into()))),
905+
Box::new(ExpectCall("sites", "getSites", Ok(no_sites()))),
885906
Box::new(ExpectSyncCommand::SyncAll),
886907
Box::new(ExpectSyncCommand::SyncAll),
887908
],

0 commit comments

Comments
 (0)