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

Method validate_name_conflict

atomic-core/src/change/graph_op.rs:417–469  ·  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

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

Calls 3

is_emptyMethod · 0.45
iterMethod · 0.45
containsMethod · 0.45