Companion to [`Self::read_for_edit`]. Performs a compare-and-swap write when both [`Self::fs_ext`] is available *and* a version token was returned by the prior read; falls back to a plain write otherwise. On version mismatch the returned error is the typed [`WorkspaceError::VersionConflict`] variant; callers can also still downcast `anyhow::Error::downcast_ref:: ()` when t
(
&self,
path: &WorkspacePath,
content: &str,
expected_version: Option<&str>,
)
| 739 | /// downcast `anyhow::Error::downcast_ref::<WorkspaceVersionConflict>()` |
| 740 | /// when the value has been lifted into an `anyhow::Result`. |
| 741 | pub async fn write_for_edit( |
| 742 | &self, |
| 743 | path: &WorkspacePath, |
| 744 | content: &str, |
| 745 | expected_version: Option<&str>, |
| 746 | ) -> WorkspaceResult<WorkspaceWriteOutcome> { |
| 747 | if let (Some(ext), Some(version)) = (self.fs_ext(), expected_version) { |
| 748 | let path = path.clone(); |
| 749 | let content = content.to_string(); |
| 750 | let expected = version.to_string(); |
| 751 | return self |
| 752 | .run_with_timeout("write_text_if_version", async move { |
| 753 | ext.write_text_if_version(&path, &content, &expected).await |
| 754 | }) |
| 755 | .await; |
| 756 | } |
| 757 | let fs = self.fs(); |
| 758 | let path = path.clone(); |
| 759 | let content = content.to_string(); |
| 760 | self.run_with_timeout( |
| 761 | "write_text", |
| 762 | async move { fs.write_text(&path, &content).await }, |
| 763 | ) |
| 764 | .await |
| 765 | } |
| 766 | |
| 767 | pub fn local_root(&self) -> Option<&Path> { |
| 768 | self.local_root.as_deref() |
no test coverage detected