(State(endpoint): State<Endpoint>, headers: HeaderMap, body: Bytes)
| 187 | ) |
| 188 | } |
| 189 | async fn pull(State(endpoint): State<Endpoint>, headers: HeaderMap, body: Bytes) -> Response { |
| 190 | if !supported(&headers) { |
| 191 | return error("acceptance endpoint requires actual binary sync protocol"); |
| 192 | } |
| 193 | let wants = match SyncWants::decode(&body) { |
| 194 | Ok(w) => w, |
| 195 | Err(e) => return error(e), |
| 196 | }; |
| 197 | let store = endpoint.store.lock().unwrap(); |
| 198 | let mut names: BTreeSet<String> = if wants.refs.is_empty() { |
| 199 | store.refs.keys().cloned().collect() |
| 200 | } else { |
| 201 | wants |
| 202 | .refs |
| 203 | .iter() |
| 204 | .filter(|n| store.refs.contains_key(*n)) |
| 205 | .cloned() |
| 206 | .collect() |
| 207 | }; |
| 208 | loop { |
| 209 | let mut added = Vec::new(); |
| 210 | for name in &names { |
| 211 | if let Some(key) = store.refs.get(name) { |
| 212 | if let Some(object) = store.objects.get(&("views".into(), key.clone())) { |
| 213 | if let Some(parent) = |
| 214 | ViewSnapshot::from_bytes(&object.bytes).and_then(|s| s.parent_view) |
| 215 | { |
| 216 | if !names.contains(&parent) && store.refs.contains_key(&parent) { |
| 217 | added.push(parent); |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | if added.is_empty() { |
| 224 | break; |
| 225 | } |
| 226 | names.extend(added); |
| 227 | } |
| 228 | // Generous fixture inventory: full pulls receive every previously uploaded |
| 229 | // non-have object. This isn't a production view authorization policy. |
| 230 | let objects = store |
| 231 | .objects |
| 232 | .values() |
| 233 | .filter(|o| { |
| 234 | if wants.refs_only { |
| 235 | o.family == ObjectFamily::View |
| 236 | } else { |
| 237 | o.family == ObjectFamily::View || !wants.haves.contains(&o.key) |
| 238 | } |
| 239 | }) |
| 240 | .cloned() |
| 241 | .collect(); |
| 242 | let refs = names |
| 243 | .into_iter() |
| 244 | .filter_map(|name| { |
| 245 | store.refs.get(&name).map(|key| RefRecord { |
| 246 | name: name.clone(), |
nothing calls this directly
no test coverage detected