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

Method validate_content_ranges

atomic-core/src/change/span_patch.rs:190–231  ·  view source on GitHub ↗

Check local byte bounds. Dependency closure, file ownership, and conflicts must additionally be checked against repository state.

(&self, content_len: u64)

Source from the content-addressed store, hash-verified

188 /// Check local byte bounds. Dependency closure, file ownership, and
189 /// conflicts must additionally be checked against repository state.
190 pub fn validate_content_ranges(&self, content_len: u64) -> Result<(), SpanPatchError> {
191 if self.version != 1 && self.version != VERSION && self.version != LEGACY_SOURCE_VERSION {
192 return Err(SpanPatchError::UnsupportedVersion(self.version));
193 }
194 if self.version == 1 && !self.semantic_owners.is_empty() {
195 return Err(SpanPatchError::InvalidEncoding);
196 }
197 SemanticNameFrame::new(self.semantic_owners.clone())
198 .map_err(|_| SpanPatchError::InvalidEncoding)?;
199 for (index, op) in self.ops.iter().enumerate() {
200 let reason = match op {
201 SpanOp::Root { start, end, .. } if start > end || *end > content_len => {
202 Some("root range is reversed or outside the contents")
203 }
204 SpanOp::Edit { file, target, .. }
205 if file.owner == Hash::NONE || target.owner == Hash::NONE =>
206 {
207 Some("file and target owners must be real changes")
208 }
209 SpanOp::Edit { target, .. } if target.start > target.end => {
210 Some("target span is reversed")
211 }
212 SpanOp::Edit {
213 target, start, end, ..
214 } if start > end || *end > target.end.saturating_sub(target.start) => {
215 Some("edit range is reversed or outside the target span")
216 }
217 SpanOp::Edit {
218 insert_start,
219 insert_end,
220 ..
221 } if insert_start > insert_end || *insert_end > content_len => {
222 Some("inserted range is reversed or outside the contents")
223 }
224 _ => None,
225 };
226 if let Some(reason) = reason {
227 return Err(SpanPatchError::InvalidOperation { index, reason });
228 }
229 }
230 Ok(())
231 }
232}
233
234/// Resolve a span change's authored semantic IDs under a receiving transaction.

Callers 3

index_changeFunction · 0.45
localize_file_opsFunction · 0.45
validate_v2Method · 0.45

Calls 3

is_emptyMethod · 0.45
cloneMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected