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