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

Method execute_restore_path

atomic-repository/src/repository/switch.rs:1364–1488  ·  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

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