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

Function apply_set_attr

atomic-core/src/apply/attribute.rs:14–58  ·  view source on GitHub ↗

Apply a `SetAttr` operation after structural graph atoms for the change. Validation and inode resolution complete before either attribute index is mutated. Reapplication of the same event is idempotent.

(
    txn: &mut T,
    change_id: NodeId,
    operation: &GraphOp<Option<Hash>>,
)

Source from the content-addressed store, hash-verified

12/// Validation and inode resolution complete before either attribute index is
13/// mutated. Reapplication of the same event is idempotent.
14pub fn apply_set_attr<T>(
15 txn: &mut T,
16 change_id: NodeId,
17 operation: &GraphOp<Option<Hash>>,
18) -> LocalApplyResult<bool>
19where
20 T: InodeAttrMutTxnT + TreeTxnT,
21{
22 let GraphOp::SetAttr {
23 inode,
24 path: _,
25 value,
26 } = operation
27 else {
28 return Ok(false);
29 };
30
31 value
32 .validate()
33 .map_err(|error| LocalApplyError::Internal {
34 message: format!("invalid SetAttr value: {error}"),
35 })?;
36 let position = resolve_position(txn, inode, change_id)?;
37 if position.change == NodeId::ROOT {
38 return Err(LocalApplyError::Internal {
39 message: "SetAttr cannot target ROOT".to_string(),
40 });
41 }
42 let repository_inode = txn
43 .position_inode(position)
44 .map_err(|error| LocalApplyError::Internal {
45 message: format!("failed to resolve SetAttr inode: {error}"),
46 })?
47 .ok_or_else(|| LocalApplyError::Internal {
48 message: format!("SetAttr target {position:?} has no repository inode"),
49 })?;
50 let event =
51 InodeAttrEvent::new(change_id, *value).map_err(|error| LocalApplyError::Internal {
52 message: error.to_string(),
53 })?;
54 txn.put_inode_attr_event(repository_inode, position, event)
55 .map_err(|error| LocalApplyError::Internal {
56 message: format!("failed to persist SetAttr: {error}"),
57 })
58}
59
60#[cfg(test)]
61mod tests {

Callers 2

import_sandbox_sliceMethod · 0.85

Calls 4

resolve_positionFunction · 0.85
put_inode_attr_eventMethod · 0.80
validateMethod · 0.45
position_inodeMethod · 0.45

Tested by

no test coverage detected