Delete a vault entry by path. Also updates the manifest.
(&self, path: &str)
| 366 | |
| 367 | /// Delete a vault entry by path. Also updates the manifest. |
| 368 | pub fn vault_delete(&self, path: &str) -> Result<bool, RepositoryError> { |
| 369 | let mut txn = self |
| 370 | .pristine |
| 371 | .write_txn() |
| 372 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 373 | use atomic_core::pristine::{EmbeddingsMutTxnT, KgMutTxnT, VaultMutTxnT, VaultTxnT}; |
| 374 | |
| 375 | let previous_entry = txn |
| 376 | .get_vault_entry(path) |
| 377 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 378 | let now = chrono::Utc::now().to_rfc3339(); |
| 379 | let cascade_updates = if let Some(previous_entry) = previous_entry.as_ref() { |
| 380 | unlink_goal_from_intent_entries(&mut txn, path, previous_entry, &now)? |
| 381 | } else { |
| 382 | Vec::new() |
| 383 | }; |
| 384 | let entry_type = previous_entry |
| 385 | .as_ref() |
| 386 | .map(|entry| entry.entry_type) |
| 387 | .unwrap_or_else(|| infer_entry_type(path)); |
| 388 | |
| 389 | txn.init_kg() |
| 390 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 391 | |
| 392 | let existed = txn |
| 393 | .del_vault_entry(path) |
| 394 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 395 | |
| 396 | // KG and embeddings are derived from the Vault entry. Clean both even |
| 397 | // if the source entry is already missing so a retry repairs stale data. |
| 398 | let node_id = super::vault_triples::entry_subject(path, entry_type); |
| 399 | txn.del_kg_node(&node_id) |
| 400 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 401 | txn.del_embeddings(path) |
| 402 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 403 | |
| 404 | if existed { |
| 405 | let mut manifest = txn |
| 406 | .get_vault_manifest() |
| 407 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 408 | update_manifest_for_delete(&mut manifest, path, previous_entry.as_ref(), &now); |
| 409 | apply_cascaded_intent_manifest_updates(&mut manifest, &cascade_updates, &now); |
| 410 | txn.put_vault_manifest(&manifest) |
| 411 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 412 | } |
| 413 | |
| 414 | txn.commit() |
| 415 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 416 | for update in cascade_updates { |
| 417 | self.vault_auto_index(&update.path); |
| 418 | if let Err(error) = self.vault_materialize(&update.path) { |
| 419 | log::warn!( |
| 420 | "Failed to materialize Intent '{}' after Goal deletion: {}", |
| 421 | update.path, |
| 422 | error |
| 423 | ); |
| 424 | } |
| 425 | } |