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

Function apply_create

atomic-core/src/crdt/apply/trunk.rs:109–147  ·  view source on GitHub ↗

Applies a Create operation to create a new file. # Behavior 1. Checks if the trunk ID already exists (error if so, unless duplicates allowed) 2. Checks if the path is already taken (error if so) 3. Allocates a new inode 4. Creates the trunk entry in TRUNKS table 5. Updates PATH_TRUNK and INODE_TRUNK indexes # Errors - `TrunkAlreadyExists` - The trunk ID is already in use - `PathAlreadyExists`

(
    txn: &mut T,
    context: &mut ApplyContext,
    trunk_id: TrunkId,
    path: &str,
    encoding: Option<Encoding>,
)

Source from the content-addressed store, hash-verified

107/// - `TrunkAlreadyExists` - The trunk ID is already in use
108/// - `PathAlreadyExists` - The path is occupied by another file
109fn apply_create<T: MutCrdtTxnT>(
110 txn: &mut T,
111 context: &mut ApplyContext,
112 trunk_id: TrunkId,
113 path: &str,
114 encoding: Option<Encoding>,
115) -> ApplyResult<()> {
116 // Check for duplicate ID
117 if txn
118 .has_trunk(trunk_id)
119 .map_err(|e| storage_err(e, "checking trunk exists"))?
120 {
121 if context.options().allow_duplicate_ids() {
122 context.record_skipped();
123 return Ok(());
124 }
125 return Err(ApplyError::trunk_already_exists(trunk_id));
126 }
127
128 // Check for path collision
129 if let Some(existing) = txn
130 .get_trunk_by_path(path)
131 .map_err(|e| storage_err(e, "checking path exists"))?
132 {
133 return Err(ApplyError::path_already_exists(path, existing));
134 }
135
136 // Allocate inode and create trunk
137 let inode = txn
138 .alloc_inode()
139 .map_err(|e| storage_err(e, "allocating inode"))?;
140 let trunk = Trunk::new(trunk_id, inode, path.to_string(), encoding);
141
142 txn.put_trunk(&trunk)
143 .map_err(|e| storage_err(e, "inserting trunk"))?;
144
145 context.record_trunk_created();
146 Ok(())
147}
148
149// Delete Operation
150

Callers 1

apply_trunk_opFunction · 0.85

Calls 9

storage_errFunction · 0.85
allow_duplicate_idsMethod · 0.80
record_trunk_createdMethod · 0.80
has_trunkMethod · 0.45
optionsMethod · 0.45
record_skippedMethod · 0.45
get_trunk_by_pathMethod · 0.45
alloc_inodeMethod · 0.45
put_trunkMethod · 0.45

Tested by

no test coverage detected