Bind only the canonical legacy FileAdd identity needed by a version-3 span edit. This is a small derived index, never content or a numeric-name alias. The caller must abort the transaction if subsequent validation refuses.
(
txn: &mut WriteTxn<'_>,
store: &S,
change: &Change,
)
| 56 | /// edit. This is a small derived index, never content or a numeric-name alias. |
| 57 | /// The caller must abort the transaction if subsequent validation refuses. |
| 58 | pub fn prepare_legacy_files<S: ChangeStore>( |
| 59 | txn: &mut WriteTxn<'_>, |
| 60 | store: &S, |
| 61 | change: &Change, |
| 62 | ) -> Result<()> { |
| 63 | let Some(patch) = &change.hashed.span else { |
| 64 | return Ok(()); |
| 65 | }; |
| 66 | if patch.version != crate::change::span_patch::LEGACY_SOURCE_VERSION { |
| 67 | return Ok(()); |
| 68 | } |
| 69 | ensure!( |
| 70 | txn.legacy_span_enabled()?, |
| 71 | "legacy span context capability missing" |
| 72 | ); |
| 73 | let ids = change |
| 74 | .dependencies() |
| 75 | .iter() |
| 76 | .map(|hash| { |
| 77 | txn.get_internal(hash)? |
| 78 | .context("legacy span dependency missing") |
| 79 | }) |
| 80 | .collect::<Result<Vec<_>>>()?; |
| 81 | let deps = EffectiveProjectionClosure::try_from_membership( |
| 82 | txn, |
| 83 | &ViewMembershipSet::from_ordered(ids), |
| 84 | )?; |
| 85 | for op in &patch.ops { |
| 86 | if let SpanOp::Edit { file, .. } = op { |
| 87 | if txn.span_file_inode(file)?.is_none() { |
| 88 | let source = store.get_verified_change(&file.owner)?; |
| 89 | source.check_hash(&file.owner)?; |
| 90 | let meta = legacy::metadata(file.owner, source.change()); |
| 91 | let pos = meta |
| 92 | .file_position(file.ordinal) |
| 93 | .context("legacy file ordinal has no FileAdd")?; |
| 94 | ensure!( |
| 95 | source.change().hashed.span.is_none(), |
| 96 | "typed span file index is missing; legacy identity cannot replace it" |
| 97 | ); |
| 98 | let owner = txn |
| 99 | .get_internal(&file.owner)? |
| 100 | .context("legacy file owner missing")?; |
| 101 | ensure!( |
| 102 | deps.contains(owner), |
| 103 | "legacy file owner outside dependency closure" |
| 104 | ); |
| 105 | let inode = super::TreeTxnT::position_inode( |
| 106 | txn, |
| 107 | crate::Position::new(owner, crate::ChangePosition::new(pos)), |
| 108 | )? |
| 109 | .context("legacy canonical inode missing")?; |
| 110 | txn.txn |
| 111 | .open_table(FILES)? |
| 112 | .insert(&file_key(file), inode.get())?; |
| 113 | } |
| 114 | } |
| 115 | } |
no test coverage detected