MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / delete_view

Method delete_view

atomic-repository/src/repository/views.rs:384–446  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

382 /// - The view is the current view (cannot delete current view)
383 /// - The database operation fails
384 pub fn delete_view(&mut self, name: &str) -> Result<(), RepositoryError> {
385 // Cannot delete the current view
386 if name == self.current_view {
387 return Err(RepositoryError::CannotDeleteCurrentView {
388 name: name.to_string(),
389 });
390 }
391
392 let mut txn = self
393 .pristine
394 .write_txn()
395 .map_err(|e| RepositoryError::Database(e.to_string()))?;
396
397 // Get the view to delete
398 let view = txn
399 .get_view(name)
400 .map_err(|e| RepositoryError::Database(e.to_string()))?
401 .ok_or_else(|| RepositoryError::ViewNotFound {
402 name: name.to_string(),
403 })?;
404
405 // Delete the view.
406 //
407 // `del_view` enforces:
408 // - Shared views cannot be deleted (returns CannotDeleteSharedView)
409 // - Views with children cannot be deleted (returns ViewHasChildren)
410 // Remove workspace directory for this view before deleting
411 // the view from the database. This cleans up any shelved
412 // artifacts (node_modules, dist, etc.) that were stored when
413 // the user last switched away from this view.
414 let ws = workspace_path(&self.dot_dir, name);
415 if ws.is_dir() {
416 let _ = std::fs::remove_dir_all(&ws);
417 }
418
419 txn.del_view(&view).map_err(|e| match &e {
420 atomic_core::pristine::PristineError::CannotDeleteSharedView { name } => {
421 RepositoryError::InvalidOperation {
422 message: format!(
423 "cannot delete shared view '{}': shared views are permanent. \
424 Use 'view new' to create a draft view instead.",
425 name
426 ),
427 }
428 }
429 atomic_core::pristine::PristineError::ViewHasChildren { name, children } => {
430 RepositoryError::InvalidOperation {
431 message: format!(
432 "cannot delete view '{}': has child views ({}). \
433 Delete or reparent children first.",
434 name,
435 children.join(", ")
436 ),
437 }
438 }
439 _ => RepositoryError::Database(e.to_string()),
440 })?;
441

Callers 8

run_popMethod · 0.80
run_dropMethod · 0.80
run_clearMethod · 0.80
runMethod · 0.80
test_delete_viewFunction · 0.80

Calls 6

workspace_pathFunction · 0.85
write_txnMethod · 0.80
is_dirMethod · 0.80
del_viewMethod · 0.80
commitMethod · 0.80
get_viewMethod · 0.45

Tested by 4

test_delete_viewFunction · 0.64