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

Method restore_original_effect

atomic-repository/src/repository/operation.rs:3199–3383  ·  view source on GitHub ↗
(
        &mut self,
        operation_lock: &WorkingCopyOperationLockGuard,
        original: &Operation,
        recovery_effect: &EffectPlan,
        target: &ResolvedRecoveryTarget,
        backup

Source from the content-addressed store, hash-verified

3197 }
3198
3199 fn restore_original_effect(
3200 &mut self,
3201 operation_lock: &WorkingCopyOperationLockGuard,
3202 original: &Operation,
3203 recovery_effect: &EffectPlan,
3204 target: &ResolvedRecoveryTarget,
3205 backup_root: &Path,
3206 ) -> Result<(), RepositoryError> {
3207 let matches: Vec<&EffectPlan> = original
3208 .payload()
3209 .delta
3210 .effects
3211 .iter()
3212 .filter(|effect| {
3213 recovery_effect.target == effect.target
3214 && recovery_effect.expected_new == effect.expected_old
3215 && recovery_effect.expected_old == effect.expected_new
3216 })
3217 .collect();
3218 let original_effect = match matches.as_slice() {
3219 [effect] => *effect,
3220 _ => {
3221 return Err(RepositoryError::InvalidOperation {
3222 message: format!(
3223 "recovery effect {} does not identify exactly one original inverse transition",
3224 recovery_effect.ordinal
3225 ),
3226 })
3227 }
3228 };
3229
3230 match (&original_effect.expected_old, target) {
3231 (EffectValue::Absent, ResolvedRecoveryTarget::Filesystem { path, .. }) => {
3232 let tombstone_root =
3233 if matches!(original_effect.target, EffectTarget::ShelfPath { .. }) {
3234 backup_root.to_path_buf()
3235 } else {
3236 self.working_copy_effect_recovery_root(
3237 operation_lock.working_copy(),
3238 original.id(),
3239 )
3240 };
3241 remove_entry_for_recovery(
3242 path,
3243 &tombstone_root
3244 .join("rolled-back-effects")
3245 .join(format!("{:010}", original_effect.ordinal)),
3246 )
3247 }
3248 (EffectValue::File(state), ResolvedRecoveryTarget::Filesystem { path, .. }) => {
3249 self.verify_backup(original, backup_root)?;
3250 let source =
3251 backup_entry_path(backup_root, original_effect.ordinal).join(BACKUP_VALUE);
3252 match state.kind {
3253 FileKind::Regular => write_atomic_regular_from_file(path, &source, state.mode),
3254 FileKind::Directory => replace_directory(path, &source, state.mode),
3255 FileKind::Symlink => replace_symlink(path, &source),
3256 FileKind::Gitlink => replace_directory(path, &source, state.mode),

Callers 1

Calls 15

backup_entry_pathFunction · 0.85
replace_directoryFunction · 0.85
replace_symlinkFunction · 0.85
openFunction · 0.85
git_oid_from_objectFunction · 0.85
verify_backupMethod · 0.80
referenceMethod · 0.80

Tested by

no test coverage detected