(repo: &Repository, pack: &SyncPack, warnings: &mut Vec<String>)
| 1024 | } |
| 1025 | |
| 1026 | fn import_sidecars(repo: &Repository, pack: &SyncPack, warnings: &mut Vec<String>) -> SidecarStats { |
| 1027 | let mut stats = SidecarStats::default(); |
| 1028 | fn short(key: &str) -> &str { |
| 1029 | &key[..12.min(key.len())] |
| 1030 | } |
| 1031 | for object in &pack.objects { |
| 1032 | match object.family { |
| 1033 | ObjectFamily::Provenance => { |
| 1034 | let Some(hash) = Hash::from_base32(object.key.as_bytes()) else { |
| 1035 | continue; |
| 1036 | }; |
| 1037 | let already_present = repo.has_provenance_graph(&hash); |
| 1038 | match atomic_core::change::ProvenanceGraph::deserialize(&object.bytes) { |
| 1039 | Ok((graph, computed)) => { |
| 1040 | if computed != hash { |
| 1041 | warnings.push(format!( |
| 1042 | "Provenance {} failed hash verification — skipped", |
| 1043 | short(&object.key) |
| 1044 | )); |
| 1045 | continue; |
| 1046 | } |
| 1047 | match repo.save_provenance_graph(&graph).map(|_hash| ()) { |
| 1048 | Ok(()) if !already_present => stats.provenance += 1, |
| 1049 | Ok(()) => {} |
| 1050 | Err(error) => warnings.push(format!( |
| 1051 | "Failed to register provenance {}: {error}", |
| 1052 | short(&object.key) |
| 1053 | )), |
| 1054 | } |
| 1055 | } |
| 1056 | Err(error) => warnings.push(format!( |
| 1057 | "Corrupt provenance {}: {error}", |
| 1058 | short(&object.key) |
| 1059 | )), |
| 1060 | } |
| 1061 | } |
| 1062 | ObjectFamily::Attest => { |
| 1063 | let Some(hash) = Hash::from_base32(object.key.as_bytes()) else { |
| 1064 | continue; |
| 1065 | }; |
| 1066 | let already_present = repo.has_attestation(&hash); |
| 1067 | match atomic_core::change::Attestation::deserialize(&object.bytes) { |
| 1068 | Ok((attestation, computed)) => { |
| 1069 | if computed != hash { |
| 1070 | warnings.push(format!( |
| 1071 | "Attestation {} failed hash verification — skipped", |
| 1072 | short(&object.key) |
| 1073 | )); |
| 1074 | continue; |
| 1075 | } |
| 1076 | match repo.save_attestation(&attestation).map(|_hash| ()) { |
| 1077 | Ok(()) if !already_present => stats.attestations += 1, |
| 1078 | Ok(()) => {} |
| 1079 | Err(error) => warnings.push(format!( |
| 1080 | "Failed to register attestation {}: {error}", |
| 1081 | short(&object.key) |
| 1082 | )), |
| 1083 | } |
no test coverage detected