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

Method complete_effects

atomic-repository/src/repository/switch.rs:239–326  ·  view source on GitHub ↗
(
        &mut self,
        target_view: &str,
        preparatory_only: bool,
    )

Source from the content-addressed store, hash-verified

237 }
238
239 fn complete_effects(
240 &mut self,
241 target_view: &str,
242 preparatory_only: bool,
243 ) -> Result<(), RepositoryError> {
244 let completed: HashSet<u32> = {
245 let txn = self
246 .repository
247 .pristine
248 .read_txn()
249 .map_err(|error| RepositoryError::Database(error.to_string()))?;
250 txn.get_effect_receipts(self.operation.id())
251 .map_err(|error| RepositoryError::Database(error.to_string()))?
252 .into_iter()
253 .filter_map(|receipt| match receipt.payload().kind {
254 EffectReceiptKind::Applied
255 | EffectReceiptKind::Recovered
256 | EffectReceiptKind::RolledBack => receipt.payload().effect_ordinal,
257 EffectReceiptKind::Verified | EffectReceiptKind::LeaseRejected => None,
258 })
259 .collect()
260 };
261 let effects: Vec<EffectPlan> = self
262 .operation
263 .payload()
264 .delta
265 .effects
266 .iter()
267 .filter(|effect| matches!(effect.target, EffectTarget::FilesystemPath { .. }))
268 .cloned()
269 .collect();
270 for effect in &effects {
271 if completed.contains(&effect.ordinal) {
272 continue;
273 }
274 if preparatory_only
275 && !effects
276 .iter()
277 .any(|later| later.ordinal > effect.ordinal && later.target == effect.target)
278 {
279 continue;
280 }
281 let EffectTarget::FilesystemPath { path } = &effect.target else {
282 continue;
283 };
284 let observed = self
285 .repository
286 .observe_filesystem_effect(self.operation_lock.working_copy(), &effect.target)?;
287 let pending = if observed == effect.expected_old {
288 let content = match &effect.expected_new {
289 EffectValue::File(state) if state.kind != FileKind::Directory => Some(
290 self.repository
291 .switch_target_file_bytes(path, target_view)?
292 .ok_or_else(|| RepositoryError::InvalidOperation {
293 message: format!(
294 "target view '{target_view}' has no bytes for leased path '{path}'"
295 ),
296 })?,

Callers 2

complete_preparatoryMethod · 0.80
complete_remainingMethod · 0.80

Calls 15

read_txnMethod · 0.80
record_effect_outcomeMethod · 0.80
collectMethod · 0.45
into_iterMethod · 0.45
get_effect_receiptsMethod · 0.45
idMethod · 0.45
payloadMethod · 0.45
iterMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected