Applies an Undelete operation to restore a deleted file. # Behavior 1. Verifies the trunk exists 2. Verifies the trunk is currently deleted 3. Updates the trunk's state to Alive # Errors - `TrunkNotFound` - The trunk doesn't exist - `InvalidTrunkState` - The trunk is not deleted
(
txn: &mut T,
context: &mut ApplyContext,
trunk_id: TrunkId,
)
| 256 | /// - `TrunkNotFound` - The trunk doesn't exist |
| 257 | /// - `InvalidTrunkState` - The trunk is not deleted |
| 258 | fn apply_undelete<T: MutCrdtTxnT>( |
| 259 | txn: &mut T, |
| 260 | context: &mut ApplyContext, |
| 261 | trunk_id: TrunkId, |
| 262 | ) -> ApplyResult<()> { |
| 263 | // Verify trunk exists |
| 264 | let trunk = txn |
| 265 | .get_trunk(trunk_id) |
| 266 | .map_err(|e| storage_err(e, "getting trunk"))? |
| 267 | .ok_or_else(|| ApplyError::trunk_not_found(trunk_id))?; |
| 268 | |
| 269 | // Check current state |
| 270 | if !trunk.state().is_deleted() { |
| 271 | if context.options().allow_duplicate_ids() { |
| 272 | context.record_skipped(); |
| 273 | return Ok(()); |
| 274 | } |
| 275 | return Err(ApplyError::invalid_trunk_state( |
| 276 | trunk_id, "alive", "undelete", |
| 277 | )); |
| 278 | } |
| 279 | |
| 280 | // Update state to alive |
| 281 | txn.update_trunk_state(trunk_id, TrunkState::Alive) |
| 282 | .map_err(|e| storage_err(e, "updating trunk state"))?; |
| 283 | |
| 284 | context.record_trunk_undeleted(); |
| 285 | Ok(()) |
| 286 | } |
| 287 | |
| 288 | // Validation Helpers |
| 289 |
no test coverage detected