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

Method execute_restore_path

atomic-repository/src/repository/switch.rs:1355–1479  ·  view source on GitHub ↗
(
        &self,
        operation_lock: &super::locks::WorkingCopyOperationLockGuard,
        prepared: &super::operation::PreparedSwitchOperation,
        target_view: &str,
        path: &str,
    

Source from the content-addressed store, hash-verified

1353 }
1354
1355 pub(super) fn execute_restore_path(
1356 &self,
1357 operation_lock: &super::locks::WorkingCopyOperationLockGuard,
1358 prepared: &super::operation::PreparedSwitchOperation,
1359 target_view: &str,
1360 path: &str,
1361 ) -> Result<(), RepositoryError> {
1362 let working_copy = operation_lock.working_copy();
1363 let shelf_target = EffectTarget::ShelfPath {
1364 working_copy,
1365 view: target_view.to_string(),
1366 path: path.to_string(),
1367 };
1368 let destination_target = EffectTarget::WorkspacePath {
1369 working_copy,
1370 path: path.to_string(),
1371 };
1372 let effects = &prepared.operation().payload().delta.effects;
1373 let shelf_effect = effects
1374 .iter()
1375 .rev()
1376 .find(|effect| {
1377 effect.target == shelf_target && effect.expected_new == EffectValue::Absent
1378 })
1379 .ok_or_else(|| RepositoryError::InvalidOperation {
1380 message: format!("switch operation omitted shelf restore source for '{path}'"),
1381 })?;
1382 let destination_effect = effects
1383 .iter()
1384 .rev()
1385 .find(|effect| {
1386 effect.target == destination_target
1387 && effect.expected_new == shelf_effect.expected_old
1388 })
1389 .ok_or_else(|| RepositoryError::InvalidOperation {
1390 message: format!("switch operation omitted shelf restore destination for '{path}'"),
1391 })?;
1392 let write = operation_lock.begin_write_immediate()?;
1393 let mut txn = write.try_lock_shelf()?;
1394 let shelf_before = self.observe_filesystem_effect(working_copy, &shelf_effect.target)?;
1395 let destination_before =
1396 self.observe_filesystem_effect(working_copy, &destination_effect.target)?;
1397 if shelf_before == shelf_effect.expected_old
1398 && destination_before == destination_effect.expected_old
1399 {
1400 let source =
1401 working_copy_workspace_path(&self.dot_dir, working_copy, target_view).join(path);
1402 let destination = self.root.join(path);
1403 let parent = destination
1404 .parent()
1405 .ok_or_else(|| RepositoryError::InvalidOperation {
1406 message: format!("shelf restore destination has no parent: '{path}'"),
1407 })?;
1408 if !parent.is_dir() {
1409 return Err(RepositoryError::InvalidOperation {
1410 message: format!(
1411 "shelf restore parent '{}' is not materialized",
1412 parent.display()

Callers 4

switch_view_journaledMethod · 0.80

Calls 14

rename_and_syncFunction · 0.85
begin_write_immediateMethod · 0.80
try_lock_shelfMethod · 0.80
parentMethod · 0.80
is_dirMethod · 0.80
working_copyMethod · 0.45
payloadMethod · 0.45
operationMethod · 0.45

Tested by

no test coverage detected