MCPcopy Create free account
hub / github.com/JamieMason/syncpack / ensure_object_path

Function ensure_object_path

src/disk.rs:667–678  ·  view source on GitHub ↗

Make sure every segment of `pointer` exists as a `Value::Object`. Walks one segment at a time, creating empty objects en route. The empty-string parent (`""`) resolves to the document root per RFC 6901.

(file: &mut File<JsonValue>, pointer: &str)

Source from the content-addressed store, hash-verified

665/// one segment at a time, creating empty objects en route. The empty-string
666/// parent (`""`) resolves to the document root per RFC 6901.
667pub fn ensure_object_path(file: &mut File<JsonValue>, pointer: &str) {
668 let segments: Vec<&str> = pointer.split('/').filter(|s| !s.is_empty()).collect();
669 let mut current = String::new();
670 for segment in segments {
671 let parent = current.clone();
672 current.push('/');
673 current.push_str(segment);
674 if !matches!(file.contents.pointer(&current), Some(JsonValue::Object(_))) {
675 set_nested_prop(file, &parent, segment, JsonValue::Object(Default::default()));
676 }
677 }
678}
679
680/// Apply an instance's `expected_specifier` to the package.json. Dispatches
681/// over the dependency type's `Strategy`. Marks the file dirty only when the

Calls 1

set_nested_propFunction · 0.85

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…