Pull from the remote's `/code` endpoint: send `wants` (which views, and the object keys already held) and decode the returned [`SyncPack`] of missing objects + current ref targets. An empty [`SyncWants::refs`] asks for every view (a full clone).
(&self, wants: &SyncWants)
| 75 | /// missing objects + current ref targets. An empty [`SyncWants::refs`] asks |
| 76 | /// for every view (a full clone). |
| 77 | pub async fn sync_pull(&self, wants: &SyncWants) -> RemoteResult<SyncPack> { |
| 78 | let url = self.base_url.as_str().to_string(); |
| 79 | let body = wants |
| 80 | .encode() |
| 81 | .map_err(|e| RemoteError::protocol(format!("failed to encode sync wants: {e}")))?; |
| 82 | let response = self |
| 83 | .client |
| 84 | .get(&url) |
| 85 | .header(PROTOCOL_HEADER, PROTOCOL_SYNC_V1) |
| 86 | .header(CONTENT_TYPE, SYNC_MEDIA_TYPE) |
| 87 | .body(body) |
| 88 | .send() |
| 89 | .await |
| 90 | .map_err(|e| RemoteError::connection_failed(&url, e))?; |
| 91 | crate::check_min_version_header(response.headers()); |
| 92 | match response.status() { |
| 93 | StatusCode::OK => { |
| 94 | let bytes = response |
| 95 | .bytes() |
| 96 | .await |
| 97 | .map_err(|e| RemoteError::connection_failed(&url, e))?; |
| 98 | SyncPack::decode(&bytes) |
| 99 | .map_err(|e| RemoteError::protocol(format!("failed to decode sync pack: {e}"))) |
| 100 | } |
| 101 | StatusCode::UNAUTHORIZED | StatusCode::FORBIDDEN => Err(RemoteError::auth_failed( |
| 102 | &url, |
| 103 | response.text().await.unwrap_or_default(), |
| 104 | )), |
| 105 | s => Err(RemoteError::http( |
| 106 | s.as_u16(), |
| 107 | response.text().await.unwrap_or_default(), |
| 108 | )), |
| 109 | } |
| 110 | } |
| 111 | } |
no test coverage detected