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

Method execute_shelve_path

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

Source from the content-addressed store, hash-verified

1139 }
1140
1141 pub(super) fn execute_shelve_path(
1142 &self,
1143 operation_lock: &super::locks::WorkingCopyOperationLockGuard,
1144 prepared: &super::operation::PreparedSwitchOperation,
1145 old_view: &str,
1146 path: &str,
1147 ) -> Result<(), RepositoryError> {
1148 let working_copy = operation_lock.working_copy();
1149 let source_target = EffectTarget::WorkspacePath {
1150 working_copy,
1151 path: path.to_string(),
1152 };
1153 let shelf_target = EffectTarget::ShelfPath {
1154 working_copy,
1155 view: old_view.to_string(),
1156 path: path.to_string(),
1157 };
1158 let effects = &prepared.operation().payload().delta.effects;
1159 let source_effect = effects
1160 .iter()
1161 .find(|effect| {
1162 effect.target == source_target && effect.expected_new == EffectValue::Absent
1163 })
1164 .ok_or_else(|| RepositoryError::InvalidOperation {
1165 message: format!("switch operation omitted workspace shelving lease for '{path}'"),
1166 })?;
1167 let final_shelf = effects.iter().find(|effect| {
1168 effect.target == shelf_target && effect.expected_new == source_effect.expected_old
1169 });
1170 if final_shelf.is_none() {
1171 let write = operation_lock.begin_write_immediate()?;
1172 let mut txn = write.try_lock_shelf()?;
1173 let before = self.observe_filesystem_effect(working_copy, &source_effect.target)?;
1174 if before == source_effect.expected_old {
1175 let source = self.root.join(path);
1176 let tombstone = self
1177 .working_copy_dot_dir()
1178 .join("operation-recovery")
1179 .join(prepared.operation().id().to_string())
1180 .join("duplicate-workspace")
1181 .join(format!("{:010}", source_effect.ordinal));
1182 if let Some(parent) = tombstone.parent() {
1183 std::fs::create_dir_all(parent)?;
1184 }
1185 rename_and_sync(&source, &tombstone)?;
1186 } else if before != source_effect.expected_new {
1187 self.append_rejected_effect_outcome(
1188 &mut txn,
1189 prepared.operation(),
1190 source_effect.ordinal,
1191 before,
1192 None,
1193 )?;
1194 txn.commit()?;
1195 return Err(RepositoryError::InvalidOperation {
1196 message: format!("duplicate workspace lease diverged for '{path}'"),
1197 });
1198 }

Callers 4

switch_view_journaledMethod · 0.80

Calls 15

rename_and_syncFunction · 0.85
is_noneMethod · 0.80
begin_write_immediateMethod · 0.80
try_lock_shelfMethod · 0.80
working_copy_dot_dirMethod · 0.80
parentMethod · 0.80
backup_rootMethod · 0.80
working_copyMethod · 0.45

Tested by

no test coverage detected