Cache side: keep change files the owner sent — each only if its bytes hash to what it claims.
(&self, changes: &[ChangeFile])
| 823 | /// Cache side: keep change files the owner sent — each only if its |
| 824 | /// bytes hash to what it claims. |
| 825 | pub fn hold_sandbox_changes(&self, changes: &[ChangeFile]) -> Result<(), RepositoryError> { |
| 826 | use atomic_core::types::Base32; |
| 827 | for (hash, bytes) in changes { |
| 828 | let (change, computed) = atomic_core::change::Change::deserialize(&mut &bytes[..]) |
| 829 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 830 | if computed != *hash { |
| 831 | return Err(RepositoryError::Database(format!( |
| 832 | "the owner sent {} as {}", |
| 833 | computed.to_base32(), |
| 834 | hash.to_base32() |
| 835 | ))); |
| 836 | } |
| 837 | self.save_change_bytes(hash, bytes, &change)?; |
| 838 | let mut txn = self.pristine.write_txn().map_err(db)?; |
| 839 | let id = txn.get_internal(hash).map_err(db)?.ok_or_else(|| { |
| 840 | RepositoryError::Database(format!("owner sent unregistered change {hash}")) |
| 841 | })?; |
| 842 | txn.put_change_deps(id, change.dependencies()).map_err(db)?; |
| 843 | txn.commit().map_err(db)?; |
| 844 | } |
| 845 | Ok(()) |
| 846 | } |
| 847 | |
| 848 | /// In a remote sandbox: load what reading or recording the working |
| 849 | /// tree needs from the owner (see [`Repository::sandbox_slice_inodes`]). |