Read a recorded build identity without creating metadata in legacy databases.
(txn: &redb::ReadTransaction, key: &str)
| 32 | |
| 33 | /// Read a recorded build identity without creating metadata in legacy databases. |
| 34 | pub fn read_version(txn: &redb::ReadTransaction, key: &str) -> PristineResult<Option<String>> { |
| 35 | let table = match txn.open_table(ATOMIC_META) { |
| 36 | Ok(table) => table, |
| 37 | Err(TableError::TableDoesNotExist(_)) => return Ok(None), |
| 38 | Err(error) => return Err(error.into()), |
| 39 | }; |
| 40 | let Some(value) = table.get(key)? else { |
| 41 | return Ok(None); |
| 42 | }; |
| 43 | let value = |
| 44 | std::str::from_utf8(value.value()).map_err(|_| super::PristineError::Inconsistent { |
| 45 | message: format!("repository build metadata {key} is not UTF-8"), |
| 46 | })?; |
| 47 | Ok(Some(value.to_owned())) |
| 48 | } |
| 49 | |
| 50 | #[cfg(test)] |
| 51 | mod tests { |
no test coverage detected