Read a file for a subsequent modify-write cycle, requesting a version token when the backend supports compare-and-swap writes. Returns `(content, Some(version))` when [`Self::fs_ext`] is available (e.g. on S3, where the version is the object ETag); `(content, None)` otherwise. Pair with [`Self::write_for_edit`].
(
&self,
path: &WorkspacePath,
)
| 711 | /// (e.g. on S3, where the version is the object ETag); `(content, None)` |
| 712 | /// otherwise. Pair with [`Self::write_for_edit`]. |
| 713 | pub async fn read_for_edit( |
| 714 | &self, |
| 715 | path: &WorkspacePath, |
| 716 | ) -> WorkspaceResult<(String, Option<String>)> { |
| 717 | if let Some(ext) = self.fs_ext() { |
| 718 | let path = path.clone(); |
| 719 | return self |
| 720 | .run_with_timeout("read_text_with_version", async move { |
| 721 | let (content, version) = ext.read_text_with_version(&path).await?; |
| 722 | Ok((content, Some(version))) |
| 723 | }) |
| 724 | .await; |
| 725 | } |
| 726 | let fs = self.fs(); |
| 727 | let path_owned = path.clone(); |
| 728 | let content = self |
| 729 | .run_with_timeout("read_text", async move { fs.read_text(&path_owned).await }) |
| 730 | .await?; |
| 731 | Ok((content, None)) |
| 732 | } |
| 733 | |
| 734 | /// Companion to [`Self::read_for_edit`]. Performs a compare-and-swap |
| 735 | /// write when both [`Self::fs_ext`] is available *and* a version token |
no test coverage detected