MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / prepare_legacy_files

Function prepare_legacy_files

atomic-core/src/pristine/span_patch_storage.rs:58–117  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

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.
58pub 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 }

Callers 2

index_changeFunction · 0.85

Calls 15

position_inodeFunction · 0.85
file_keyFunction · 0.85
is_noneMethod · 0.80
check_hashMethod · 0.80
file_positionMethod · 0.80
getMethod · 0.65
metadataFunction · 0.50
iterMethod · 0.45
dependenciesMethod · 0.45
contextMethod · 0.45
get_internalMethod · 0.45
span_file_inodeMethod · 0.45

Tested by

no test coverage detected