Delete a view from the repository. This removes the view and all its associated metadata, but does not delete the changes themselves. Changes remain in the graph and may be referenced by other views. # Arguments `name` - The name of the view to delete # Errors Returns an error if: - The view does not exist - The view is the current view (cannot delete current view) - The database operation fa
(&mut self, name: &str)
| 594 | /// - The view is the current view (cannot delete current view) |
| 595 | /// - The database operation fails |
| 596 | pub fn delete_view(&mut self, name: &str) -> Result<(), RepositoryError> { |
| 597 | self.ensure_project_identity(atomic_core::kg::project_id::MintReason::Upgrade)?; |
| 598 | // Cannot delete the current view |
| 599 | if name == self.current_view { |
| 600 | return Err(RepositoryError::CannotDeleteCurrentView { |
| 601 | name: name.to_string(), |
| 602 | }); |
| 603 | } |
| 604 | |
| 605 | let mut txn = self |
| 606 | .pristine |
| 607 | .write_txn() |
| 608 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 609 | |
| 610 | // Get the view to delete |
| 611 | let view = txn |
| 612 | .get_view(name) |
| 613 | .map_err(|e| RepositoryError::Database(e.to_string()))? |
| 614 | .ok_or_else(|| RepositoryError::ViewNotFound { |
| 615 | name: name.to_string(), |
| 616 | })?; |
| 617 | |
| 618 | // Delete the view. |
| 619 | // |
| 620 | // `del_view` enforces: |
| 621 | // - Shared views cannot be deleted (returns CannotDeleteSharedView) |
| 622 | // - Views with children cannot be deleted (returns ViewHasChildren) |
| 623 | // - Views selected by a working copy cannot be deleted |
| 624 | txn.del_view(&view).map_err(|e| match &e { |
| 625 | atomic_core::pristine::PristineError::CannotDeleteSharedView { name } => { |
| 626 | RepositoryError::InvalidOperation { |
| 627 | message: format!( |
| 628 | "cannot delete shared view '{}': shared views are permanent. \ |
| 629 | Use 'view new' to create a draft view instead.", |
| 630 | name |
| 631 | ), |
| 632 | } |
| 633 | } |
| 634 | atomic_core::pristine::PristineError::ViewHasChildren { name, children } => { |
| 635 | RepositoryError::InvalidOperation { |
| 636 | message: format!( |
| 637 | "cannot delete view '{}': has child views ({}). \ |
| 638 | Delete or reparent children first.", |
| 639 | name, |
| 640 | children.join(", ") |
| 641 | ), |
| 642 | } |
| 643 | } |
| 644 | _ => RepositoryError::Database(e.to_string()), |
| 645 | })?; |
| 646 | |
| 647 | txn.commit() |
| 648 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 649 | |
| 650 | self.kg_enrich_views()?; |
| 651 | |
| 652 | // Only clean up legacy shelved artifacts after deletion is durable. |
| 653 | // A refused deletion or failed commit must preserve the user's files. |