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

Method validate_name_conflict

atomic-core/src/change/graph_op.rs:412–464  ·  view source on GitHub ↗

Validate the exact edge-transition contract for a name-conflict operation. Other graph-operation variants are accepted unchanged. V3 serialization invokes stricter reference validation in addition to this structural check.

(&self)

Source from the content-addressed store, hash-verified

410 /// Other graph-operation variants are accepted unchanged. V3 serialization
411 /// invokes stricter reference validation in addition to this structural check.
412 pub fn validate_name_conflict(&self) -> Result<(), String> {
413 let (operation, name, path, expected_previous, expected_flag) = match self {
414 GraphOp::SolveNameConflict { name, path } => {
415 let alive = EdgeFlags::FOLDER | EdgeFlags::BLOCK;
416 (
417 "SolveNameConflict",
418 name,
419 path,
420 alive,
421 alive | EdgeFlags::DELETED,
422 )
423 }
424 GraphOp::UnsolveNameConflict { name, path } => {
425 let alive = EdgeFlags::FOLDER | EdgeFlags::BLOCK;
426 (
427 "UnsolveNameConflict",
428 name,
429 path,
430 alive | EdgeFlags::DELETED,
431 alive,
432 )
433 }
434 _ => return Ok(()),
435 };
436
437 if path.is_empty() {
438 return Err(format!("{operation} requires a non-empty surviving path"));
439 }
440 if name.edges.is_empty() {
441 return Err(format!(
442 "{operation} requires at least one losing name claim"
443 ));
444 }
445 for (index, edge) in name.edges.iter().enumerate() {
446 if edge.previous != expected_previous || edge.flag != expected_flag {
447 return Err(format!(
448 "{operation} edge {index} must transition exactly from {expected_previous:?} to {expected_flag:?}, got {:?} to {:?}",
449 edge.previous, edge.flag
450 ));
451 }
452 if edge.to.start >= edge.to.end {
453 return Err(format!(
454 "{operation} edge {index} must target a non-empty name vertex"
455 ));
456 }
457 if name.edges[..index].contains(edge) {
458 return Err(format!(
459 "{operation} edge {index} duplicates an earlier losing claim"
460 ));
461 }
462 }
463 Ok(())
464 }
465}
466
467impl GraphOp<Option<Hash>> {

Calls 3

is_emptyMethod · 0.45
iterMethod · 0.45
containsMethod · 0.45