| 34 | } |
| 35 | |
| 36 | fn list_vault_entries( |
| 37 | &self, |
| 38 | prefix: &str, |
| 39 | entry_type_filter: Option<VaultEntryType>, |
| 40 | ) -> PristineResult<Vec<VaultEntryMeta>> { |
| 41 | let table = match self.txn.open_table(VAULT_ENTRIES) { |
| 42 | Ok(table) => table, |
| 43 | Err(redb::TableError::TableDoesNotExist(_)) => return Ok(Vec::new()), |
| 44 | Err(e) => return Err(PristineError::from(e)), |
| 45 | }; |
| 46 | |
| 47 | let mut results = Vec::new(); |
| 48 | |
| 49 | let iter = if prefix.is_empty() { |
| 50 | table.iter()? |
| 51 | } else { |
| 52 | table.range(prefix..)? |
| 53 | }; |
| 54 | |
| 55 | for item in iter { |
| 56 | let (key, value) = item?; |
| 57 | let key_str = key.value(); |
| 58 | |
| 59 | // Stop iterating once we pass the prefix range |
| 60 | if !prefix.is_empty() && !key_str.starts_with(prefix) { |
| 61 | break; |
| 62 | } |
| 63 | |
| 64 | let entry: VaultEntry = |
| 65 | postcard::from_bytes(value.value()).map_err(|e| PristineError::Serialization { |
| 66 | message: format!("failed to deserialize VaultEntry at '{}': {}", key_str, e), |
| 67 | })?; |
| 68 | |
| 69 | // Apply type filter |
| 70 | if let Some(ref filter) = entry_type_filter { |
| 71 | if entry.entry_type != *filter { |
| 72 | continue; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | results.push(VaultEntryMeta { |
| 77 | path: key_str.to_string(), |
| 78 | entry_type: entry.entry_type, |
| 79 | content_hash: entry.content_hash, |
| 80 | content_size: entry.content_bytes.len(), |
| 81 | updated_at: entry.updated_at, |
| 82 | }); |
| 83 | } |
| 84 | |
| 85 | Ok(results) |
| 86 | } |
| 87 | |
| 88 | fn get_vault_manifest(&self) -> PristineResult<VaultManifest> { |
| 89 | let table = match self.txn.open_table(VAULT_MANIFEST) { |